Event-Driven Architecture in Microservices

By:

Published

Every day, the amount of data being produced grows exponentially. Data from website clicks, sensors, typed inputs, cookies, or any of the other thousands of data-gathering touch points or ‘events’. Applications are expected to handle this never-ending stream of new events, and therefore, they need to be developed accordingly to detect, keep track of, and act upon these events. This is the heart of Event-Driven Architecture (EDA).

Event-driven architecture is a design pattern that enables applications to detect events and act on these events. This method replaces more traditional request-response-type architecture, where the application or service must wait for a response before taking action. This is often referred to as synchronous communication.

In a modern microservices architecture, applications are built with decoupling in mind, and communicating between these decoupled microservices is challenging. An event-driven architecture addresses this issue of effectively communicating between decoupled microservices by providing better scalability, agility to change according to business needs, and an overall faster time to market. This is called the asynchronous communication model.

Benefits of using event-driven architecture

  • Efficient development – An event-driven architecture, being inherently scalable, provides a lot of flexibility in application development. While the initial setup time may be intensive, it requires almost no effort to scale up once it is up and running. An excellent example of this in action is an e-commerce platform, where customers are often notified in real-time about the status of their order, which leads us to the next benefit.
  • Better user experience – Event-driven architecture leads to an overall better user experience. Taking the previous example, a great online shopping experience in which the application remembers the customer’s purchase history, order statuses, browsing behavior, and general preferences leads to a much better user experience resulting in a higher customer retention rate.
  • Lower running costs – In the long run, an event-driven architecture can reduce running costs for the business. But do keep in mind where an event-driven architecture should be deployed. If your application does not have much traffic, creating an Event-driven architecture might be overkill.
  • Resiliency – An Event-driven architecture can make your applications more resilient. If a service fails, it can re-start automatically and process the events from the events data store. This helps avoid transaction loss.

Message Brokers in Microservices:
When using asynchronous communication for Microservices, it is common to use a message broker. A broker ensures that communication between different microservices is reliable and stable, and that the messages are managed and monitored within the system and that messages do not get lost. There are different message brokers available in the market. You can classify them into open source and licensed message brokers. Some of the commonly known message brokers are Kafka, RabbitMQ, Solace, ActiveMQ.

Getting Microservices to Work Together
There are 2 approaches to get microservices to work towards a common goal at a high level – Orchestration and Choreography.

Orchestration – In Orchestration, each microservice is waiting for instructions from the orchestrator. Each microservice knows what it can do, but it will not activate unless it receives a command from the orchestrator. This design pattern can help you create tightly coupled systems where each service depends on another service or an orchestrator. Orchestrator services can be a microservice or a component in a microservice, controlling other microservices.

The orchestrator service needs to communicate with all the other microservices and control what other services should do. This creates a dependency on each other when they are synchronous, and each service must expect other services to respond to make the entire system work. Failure at one level makes the whole system error-prone. Orchestration relies on Rest APIs and creates a tightly coupled system.

Choreography – In this approach, a message broker manages the exchange of messages between microservices, making this a loosely coupled system and one that does not break because of downtime in any of the microservices. All communication happens asynchronously, enabling these microservice not to wait for other services to respond. Once it receives an event, the service knows what it should do. It completes the transactions and fires off the event to notify the other services about the completion.

This also lets your services operate more independently and focus on their functions. This architecture also allows for changes to your services and adding new functionalities with less impact on the business.

Language Barriers

Most of the message brokers have their own APIs available, and language-specific implementations are available. In both options: orchestrated and choreographed, you could handle the integration seamlessly.

For example, Uber runs over 100 microservices to support its business. Python is used as one of the principal languages to create their services apart from Java and Go. There is no language restriction on developing microservices. You can decide for yourself what language and platform best suit your needs. All languages have excellent support for developing event-driven microservices. Uber’s success story proves that it is time to explore and leverage other languages and not only rely on Java and C# to develop your microservices.

Event-driven architecture and microservices have changed the way we develop our applications. Application scaling, reduced application maintenance, and faster time-to-market can all be achieved with the help of choreographed event-driven microservices.

Talk to us for a quick assessment

Get in touch

Related Posts