The benefits of adopting microservices over monolithic application development.
Microservices is used a lot when talking about building applications, especially when most new applications are developed and hosted using cloud technologies. But why is this style of application architecture gaining such popularity, what does it mean for your applications and how can you start designing applications to take advantage of this architecture? In this post, we will take a high-level view of microservices, what makes them different from traditional monolithic applications and why leveraging this architecture can show big benefits for your next application.
What are Microservices?
Before we dive into why and how to use microservices, let’s talk about what microservices are. There are a number of different versions, but essentially microservice applications are built using small, componentized services that are composed together to form complete functions and processes. Each service is generally its own self-contained function, run in its own context with its own resources. Microservices are also loosely coupled and communicate with each other using mechanisms such as RESTful APIs. This allows developers to implement each service as its own, self-contained component independent of other aspects of the application.
Monolithic vs Microservices
Because of the different approach to application development, microservice-based applications have a number of key characteristics that set them apart from traditional, monolithic applications. These main characteristics include:
- Organized by Business Function – One of the key differences is components are generally organized by a singular business function, such as make payment, view invoice, send email, etc. This makes designing and implementing functions simpler as functionality is broken down to the smallest applicable service.
- Loosely Coupled – More traditional, monolithic applications can tightly couple components together as more functionality is added and can have the same function written multiple different times as part of different business processes as they become larger. Microservices largely avoids this issue, allowing components to be written generically and reused within the application as required. It also allows components to be deployed and scaled using different metrics to supply resources to heavily used components as required, rather than scaling everything.
- Highly Maintainable – As each service is a small, componentized function, this inherently makes services highly maintainable and easily testable. As components change or others are added, deploying and testing new functionality is simplified. When looking at monolithic applications you can get lost in the code – and implementing, as well as testing, changes becomes harder and more time-consuming.
- Owned by Small Teams – Microservices are more easily carved up and owned by individuals or small teams. Rather than large development and support teams looking after a single application, each service owner can implement, change and support their services independently. Additionally, because teams own the whole service, they can make decisions on platforms, languages and technology to implement their service without affecting other services.
Benefits of Microservices
It is a significant change to your development practices when adopting a service-orientated approach but the resulting microservices application offers a lot of practical benefits. These include:
- Cloud-First – Microservices are generally built on cloud-friendly technology stacks, allowing your applications to take advantage of a number of different cloud providers, offerings and models. This includes hosting services on infrastructure you control, hosting components in containers or just building components with serverless functions. You can also host components in multiple regions with multiple providers if required. Your total cost in deploying applications into these cloud providers also decreases when compared to traditional hosting and maintenance.
- Modular – Modularity offers a number of benefits, the key being flexibility. Because services are modular you can quickly add functionality in small parts at a rapid pace, scale individual components automatically when demand is high, as well as move and swap components to form new business processes. It also allows you to integrate complex services that aren’t core to your application but can provide critical benefits, such as payment processing, pdf creation, chatbots or authentication.
- Deployment Processes – When designing services in such a way to minimize changes to their interfaces, your build and deployment processes can be improved and automated. Individual services can be built, tested and deployed with very limited impact on the current running environments. You can even get to the stage where there is zero downtime when deployments occur, allowing you to consistently push changes.
- Easier to Manage – Finding the service that is causing issues becomes a lot easier to track as you can relate failure to the function that is running under a singular service. Because services are testable and visible it is also easier to catch these errors before they cause issues. Additionally, as you add more and more features, rather than slowing due to the size and complexity of your application, feature releases can speed up as new features reuse more and more service components.
Designing, Building and Deploying Microservices
Due to the fundamental shift in the way applications are designed and delivered, adopting a microservices approach can be quite daunting. There are also no black and white rules on how to compose and deploy your functions but there is some general advice you can follow when creating a microservices application.
As mentioned early, creating services should be organized into singular business functions. In reality, this can be a lot harder than it seems. A good rule of thumb is if it is a step in a business process it should probably be a single service. For instance, if you take the example of adding a product to your cart in a web store application then adding a product, changing products and retrieving products from your cart would all be individual services.
Three Key Questions to Ask Yourself When Developing Services:
When developing individual services, a lot of thought needs to be given to the design and intent of the service being delivered.
1. Am I increasing the scope of the service or doing multiple functions?
If you start building your microservice to do more than one task, consider splitting the service into two or more.
2. Is my service generic enough to be used outside of the current request?
Rather than building microservices for the current task, think about potential different uses for the service to increase its potential reuse.
3. Is my interface complete enough to warrant no changes?
When you change a service’s interface you potentially break other services that rely on it so try to build your interface to handle as many use cases as possible.
These questions can be hard to answer but they will get you thinking about the scope and design of individual services.
Microservices Connectivity Considerations
Microservice applications rely heavily on connectivity between APIs rather than within the bounds of their system. This can mean the pipelines between services can become a bottleneck if not maintained. From the perspective of your whole application, care should be given to ensure that your messaging pipelines are performant and scalable to ensure traffic flows between services. From an individual services perspective, care should be given to how much data is both sent and received by the service to perform its function. Additionally, try and ensure all messages are asynchronous and non-blocking where appropriate so that services aren’t waiting or halted. This can be even more important once you start integrating 3rd party services and APIs.
How services are deployed and tested once written can also factor into how you design your microservices application. If you are building services to run on more traditional virtual machines, does your deployment pipeline build the infrastructure as well using templates? If your application runs in containers or leverages serverless functions will your deployment pipeline configure and scale those elements as required? It is also important to define who manages the pipeline, how changes are tested and approved so deployments can be enacted quickly.
Microservices are the Best Choice
Microservice architectures have a number of benefits over traditional, monolithic applications. It requires a very different approach and while microservices don’t necessarily fit for every application or component, this pattern can make large, complex applications more flexible and maintainable. Microservices also inherently allows you to leverage the capabilities of cloud providers and 3rd party APIs seamlessly, such as the payment services API Rapyd provides, which just doesn’t make sense to write yourself. Your application can benefit from this approach and add real value. For more information about Rapyd Collect’s global API, built on microservices architecture, check out the overview.