Choosing the right software architecture is easy when you know the various software designs/patterns and you know how it can solve your business problems/aspirations. If your business requires scalability, agile development, frequent features addition, and quick release cycles, then it might be a good option to consider Microservices architecture.
Service-Oriented Architecture (SOA) has been part of the software world for decades. But, it was during the early 2000s, when client-server architecture was booming, many started realizing the disadvantages of it. That’s when they started exploring an alternative to a monolithic approach, a need for separating applications into small units (later coined as microservices) came into existence.
Microservices, a service-oriented architecture (SOA), have small, independent services for specific objectives and use lightweight protocols (like HTTP, REST) which helps developers to quickly design, develop, test, deploy, modify and maintain.
Here’s the exact definition by James Lewis and Martin Fowler, who first invented and documented the term microservice.
“The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms.”
Why Microservices are preferred over Monolithic?
Monolithic architecture is being used for a long time. It is the fundamental approach to building an enterprise software application that catered to numerous business requirements.
Monolith architecture at the starting phase is simple to develop and deploy. However, as the requirements and functionalities increase over time, it becomes complex to maintain. Monolithic has the following disadvantages:
- To update a part of the system, the entire application has to be redeployed.
- Adopting new technologies or frameworks is very difficult because all the functionalities are built on homogeneous technologies.
- The whole application might halt even if one service goes unstable.
- Using agile methodologies in monolithic application is difficult.
To overcome the disadvantages of monolithic, non-overlapping services such as microservices are preferred. Now let us look at the advantages of microservices in detail.
Advantages of Microservices
Microservices are independently redeployable. When a single component of the application needs to be changed, that particular microservice alone can be redeployed. This aspect helps during agile development when making frequent code changes to the application and deployment to production.
Microservices approach is to split teams into micro teams that can function independently. For instance, each team will have a mix of UI specialists, middleware specialists and DBAs rather than having all UI specialists in one team, database specialists in another team and a third team full of middleware specialists.
Decentralized Data Management
Microservices architecture has a private database for each microservice to implement a particular business function. In case, one particular microservice needs to access the data available with other microservice, it can do so via API calls.
Microservices are self-governing entities in a software application. Whether it is design or implementation of functionalities, microservices can function independently without a common standard of governance. When the need arises to use common services like security requirements, monitoring, throttling, etc., microservices communicate through APIs.
Standard API-security protocols, OAuth2, and OpenID Connect are used in a microservice architecture. OAuth2 allows access when a ‘by-reference token’ or ‘Access token’ is provided during authentication. OpenID Connect uses both the access token and ID token for authentication. ID token, as the name suggests, contains user information.
Service Registry and Service Discovery
Microservices are registered with the help of service registry. Why service registry is required? When teams develop microservices independently there are chances that they have developed duplicate microservices. When a service registry is available, the teams can share and use microservices optimally.
The registry contains the location of the microservice and the various instances. To identify a specific microservice in the Service Registry, a discovery mechanism is required. Client-side Discovery and Server-side Discovery are mechanisms used to identify a microservice.
In client-side discovery, the API gets the location by querying the Service Registry directly. In Server-side discovery, the request is first sent to the load balancer running on a known location and then the load balancer calls the service registry to determine the microservice location.
Codes and languages of your choice
Microservices approach solves development problems by allowing different teams to pick their own codes/languages (Java, C++, J Script).
Brands using Microservices
Microservices are used by major players in the tech industry including Amazon, Netflix, Twitter, PayPal, eBay and Uber and the list goes on.
How to design a Microservice?
Defining the boundaries of microservices and aligning them with the business requirements is essential during the design phase.
A microservice should be designed in such a way that each microservice should have focus towards only one specific functionality in the software. Assigning more than one functionality to a microservice is generally considered a bad design. Microservices architecture helps accommodate agile development and delivery methodologies.
To design a microservices, you need to get the following aspects right:
To achieve efficient ‘messaging’ in a microservices architecture, you need lightweight mechanisms. REST (Representational State Transfer) and Thrift architectural types are for synchronous messaging and AMQP, STOMP or MQTT are for asynchronous messaging. With regard to message formats, JSON, XML and for service interfaces, Swagger, RAML and Thrift IDL (Interface Description Language) are available.
To integrate microservices in a software application, you need protocols and gateways. There are many approaches to implement gateways such as point-to-point and API-Gateway.
- Communication between the services and clients cannot be monitored, traced or filtered.
- Implementation of common functionalities like end-user authentication has to be repeated for each and every microservice.
API-Gateway (API-GW) approach combines both microservices and API management and acts as a bridge between the client and microservices. The advantages of API gateway are:
- Ability to expose different APIs to different clients.
- Non-functional capabilities like security, monitoring are implemented at the Gateway- level and not repeated at every microservice-level.
- Lightweight and quick communication is achieved at microservices-level.
Microservices deployment should satisfy requirements such as:
- Deploy or undeploy each microservice independently.
- Building and deploying microservices should be easy and quick.
- Ability to scale at microservice-level to handle more traffic for specific service.
- Even if one microservice fails it should not affect the functioning of other microservices.
Introducing Microservices Tools & Terminologies
There are various tools & terminologies required for designing a Microservices architecture. Let’s explore some of them here.
RabbitMQ is the widely used open source message broker tool. It can be used to connect two or microservices in a microservices architecture to scale applications and can be used to exchange events between services as well.
Apache Kafka is a distributed event streaming platform and can be used for communication between microservices. The advantage of Kafka is that, the sender is oblivious of the receiver. Further, it helps achieve a centralized security control because you can set Access Control Lists (ACL) limiting specific senders and receivers to access specific data in the system.
Apache Zookeeper can be used to manage microservices especially when migrating from monolithic architecture. Both Kafka and Zookeeper can be used for message queuing between microservices and external sources.
The basic flow here is to start Zookeeper and kafka server as a broker that mediates messages between publisher and subscriber. Then comes the producer API is called to create message and the consumer API that consumes message from kafka queue.
Service Registry – Eureka, Zookeeper, Consul
Eureka is a service directory where every microservice is registered. When a client microservice needs to communicate with another microservice, it first contacts the Eureka server and then through the servier, the dependent microservice is contacted. Consul is a service directory like Eureka. Microservices can communicate using Consul service directory.
For microservices communication, circuit breakers are needed to trace any failure between distributed services. Hystrix and Jrugged are among the preferred circuit breakers.
Jrugged is a Java. fault-tolerant library used to build production-ready server code in Java. It provides simple circuit breaker implementation with a few monitoring capabilities. However, it lacks the much expected features from fault tolerance library such as fallbacks or bulkheads.
Hystrix or Netflix is implemented to trace and control latency/failure between distributed services. It continuously monitors the calls and when any dependent service response exceeds a threshold limit, it breaks the circuit.
A fallback policy is put in place so that all the requests go through that fallback path while the dependent source is given time to recover. After a preset time, the circuit is closed for the request to flow normally.
Zuul is a microservice acting as an API gateway. Also known as Edge service, it receives requests from the front-end UI and allocates the requests to appropriate internal microservices at the backend.
Netty is an event-driven client/server framework/gateway used for developing high-performance protocol servers and clients. It supports FTP, SMTP, HTTP, UDP and TCP applications.
Finagle is an Apache-licensed RPC stack, developed by Twitter and is written in Scala. It is based on asynchronous NIO APIs and both its servers and clients are built on top of Netty.
Identity and Access Management
Identity and access management (IAM) ensures that the internal, intra-application communications among microservices are secure.
Kerberos is an authentication tool that can secure big data products including Apache Kafka. In microservices architecture, Kerberos is used to achieve single sign (authentication) on functionality.
OAuth3 is an authorization protocol that allows users to access specific data using web/desktop/mobile apps.
OpenID Connect is based on OAuth3 and used for authorization. It uses UserInfo, ID Token and other parameters over OAuth3. However, it cannot be used for authentication.
Microservices Dashboard app allows to visualize links between microservices and other ecosystems that encompass it. It consists of UI, Resources, Backends and Microservices as columns. Elasticsearch can analyze large data volumes.
Kibana is a plugin that helps visualize Elasticsearch data. Together, Kibana and Elasticsearch can be used to host a cloud service on Amazon Web Services.
Splunk feteches a data pile and lets people search the pile to extract the information they require. The three key components of Splunk are: forwarder, indexers and search head. Forwarder sends the data to remote indexers. Indexers, as the name suggests, is responsible for storing and indexing data. Search head is the front-end of the web interface.
Log Aggregation, as the name suggests, is the process of aggregating log files in order to organize the data for easy searching.
Logstash, like Splunk, is also a log aggregator. It can take logs from different sources and with the help of input plugins, filter the data and sends the desired output.
Metrics help understand how your microservices architecture performs. When service traffic is passed through a service mesh that gathers telemetry data, it automatically collects fine-grained, high-level app information. These metrics include data like Success rates, Request volume, Request duration, Request size. Request and error counts, Latency and HTTP Error codes. Based on the metrics, you can optimize the performance of your architecture.
Dropwizard has a collection of best-in-class libraries to support application metrics, logging etc., In microservices, Dropwizard can be used for its various features like standalone server and single JAR.
Actuator or Spring boot Actuator offers various production-grade services to the application such as logs, metrics, environment variables etc., These information can be exposed by Actuator endpoints via HTTP, JMX or by logging in directly through SSH.
Prometheus is an open source project by SoundCloud and in microservices context, it support multi-dimensional data collection. The main strength of Prometheus is its ‘querying’ capabilities with which it can help quickly diagnose problems. Prometheus server runs independently and so, even if a few parts in the architecture fails, it can still rely on the server to view the system statistics.
Containers are lightweight envelops assigned for each Microservice making the software portable. It has the required code to execute the specific Microservice instance. The advantage of Container is that it can be dynamically created and destroyed which allows micoservices to be scalable and highly available.
Docker is a containerization platform. A Docker container encapsulates a Microservice and responsible for a particular business functionality. With the help of Dockers, encapsulate each microservice in the architecture and make the application run regardless of the host environment. Docker can integrate popular tools and services including Amazon Web Services and Microsoft Azure.
Rocket or CoreOS rkt is a container runtime, an alternate to the Docker. Rocket consists of two elements, Actool, the first element is responsible for building container, handling its validation and discovery. The second element rkt (pronounced as Rocket) fetches and runs container images.
The advantages of Rocket container are:
- independent composition (download/install/run) of containers
- Security isolation that is pluggable and includes image auditing
- simple discovery of container images and independent deployment
- well-specified runtime so that tools are implemented consistently
Orchestrator is responsible for coordinating front-end and back-end tasks especially in a microservices architecture.
Kubernetes is an orchestration platform created by Google, used to solve challenges in designing a microservice architecture such as traffic routing, distributed monitoring, service discoveries and so on. Kubernetes is language agnostic and open source as well.
Mesos or Apache Mesos is a cluster manager. It separates data centre resources in order to ease the deployment and management of distributed applications. Mesos, along with DC/OS (mesosphere-backed framework) built on top of Mesos and Apache Kafka, can achieve highly-scalable streaming infrastructure and cloud-native platform.
Docker Swarm is a container orchestration platform. It is a container management service and a native clustering engine for and by Docker. Any tool or service running with Docker containers will run in Docker Swarm as well. Docker Swarm is easy to setup and helps quick container deployment.
Continuous Delivery (CD)
Continuous Delivery (CD) in microservice architecture is challenging because of four major reasons:
- Complexity of the distributed system makes it difficult to maintain the integrity.
- Managing frequent feature releases especially when many microservices are involved.
- Deploying disparate technology stacks is challenging.
- Best-suitable tools for CD workflows can be hard to find.
To achieve CD on Microservices, you need to have an effective test strategy, evaluate your current CD practices, a proper plan to use various environments, managing configuration and preparation for instability and bugs.
Jenkins or Jenkins X is an open source system to achieve continuous integration, continuous delivery (CI/CD) and automated testing in Kubernetes. It is responsible for microservices deployment pipeline which saves time to create pipelines for each microservice.
Asgard is a web interface for cloud management and application deployments. It is part of the open source Netflix projects and released under the Apache Licence (v 2.0).
Aminator is one of the AMI creation tools and used for creating custom Amazon Machine Images (AMIs).
Externalization Configuration is a pattern in which an application is run in multiple environments like development, testing, production without any code modifications in the application. Externalized configuration stores the configuration information including database, file system, environmental variables in an external store.
During the start of the application, microservices will load the configuration from the external store. When running, microservices have an option to reload the same configuration. This prevents any service restart.
Consul is a distributed service mesh. It can be used to connect and configure services in any runtime platform and cloud. It provides service discovery, health monitoring and config services. In short, it can be termed as a combination of DNS server plus ZooKeeper for service discovery and Nagios for health monitoring all rolled up into one system.
Decider is a state machine service and monitors the workflow events such as task completion and failure. It checks the current state of the workflow and identifies the next state. Later, it schedules the tasks and updates the status of the workflow. To schedule tasks, Decider uses a distributed queue (eg: dyno-queues).
Archaius is a configuration management library. It uses java configuration management APIs and an extension of Commons Configuration Library (Apache).
And there are other aspects to be taken care of such as Auditing, Exception Tracking, Alerting, Rate limiting, Distributed tracing and Health Check API.
By knowing Microservices Architecture (MSA), its advantages and benefits, the various terminologies associated with Microservices, you may have a fair idea of whether it will suit your business requirements.
If you are planning to migrate from a monolithic architecture to microservices or to develop a new software application or to move your eCommerce system to MSA, Ziffity can help.