Skip to main content

EVENT DRIVEN MICROSERVICES

EVENT BASED MICROSERVICES - Event Sourcing

In a Microservice Architecture, especially with Database per Microservice, the Microservices need to exchange data. For resilient, highly scalable, and fault-tolerant systems, they should communicate asynchronously by exchanging Events. In such a case, you may want to have Atomic operations, e.g., update the Database and send the message. If you have SQL databases and want to have distributed transactions for a high volume of data, you cannot use the two-phase locking (2PL) as it does not scale. If you use NoSQL Databases and want to have a distributed transaction, you cannot use 2PL as many NoSQL databases do not support two-phase locking. In such scenarios, use Event based Architecture with Event Sourcing. In traditional databases, the Business Entity with the current “state” is directly stored. In Event Sourcing, any state-changing event or other significant events are stored instead of the entities. It means the modifications of a Business Entity is saved as a series of immutable events. The State of a Business entity is deducted by reprocessing all the Events of that Business entity at a given time. Because data is stored as a series of events rather than via direct updates to data stores, various services can replay events from the event store to compute the appropriate state of their respective data stores.

Pros

  • Provide atomicity to highly scalable systems.
  • Automatic history of the entities, including time travel functionality.
  • Loosely coupled and event-driven Microservices.

Cons

  • Reading entities from the Event store becomes challenging and usually need an additional data store (CQRS pattern)
  • The overall complexity of the system increases and usually need Domain-Driven Design.
  • The system needs to handle duplicate events (idempotent) or missing events.
  • Migrating the Schema of events becomes challenging.

When to use Event Sourcing

  • Highly scalable transactional systems with SQL Databases.
  • Transactional systems with NoSQL Databases.
  • Highly scalable and resilient Microservice Architecture.
Typical Message Driven or Event-Driven systems (e-commerce, booking, and reservation systems).

When not to use Event Sourcing

  • Lowly scalable transactional systems with SQL Databases.
  • In simple Microservice Architecture where Microservices can exchange data synchronously (e.g., via API).

Enabling Technology Examples


Event Store: EventStoreDB, Apache Kafka, Confluent Cloud, AWS Kinesis, Azure Event Hub, GCP Pub/Sub, Azure Cosmos DB, MongoDB, Cassandra, Amazon DynamoDB.
Frameworks: Lagom, Akka, Spring, akkatecture, Axon, Eventuate

Comments

Popular posts from this blog

Basics Of Hadoop Ecosystem - 2

Basics of Hadoop Ecosystem – 2 Apache Ambari is a web-based tool for provisioning, managing, and monitoring Apache Hadoop clusters. It has a very simple yet highly interactive UI to install various tools and perform various management, configuration and monitoring tasks.  Introduction: In part 2 of the blog series I will cover the other core components of a Hadoop Framework including querying part, external integration, data exchange, co-ordination and managing as well as monitoring of Hadoop Clusters. Please refer to Basic’s of Hadoop Ecosystem  Part 1 ... QUERYING: Pig seems quite useful however; I am more of an SQL person. For those of us who still like SQL, we have SQL for Hadoop. HIVE Hive is a distributed data warehouse built on atop of HDFS to manage and organize large amounts of data. It provides a query based on SQL semantics  (HiveQL)  which is translated by the runtime engine to Map Reduce jobs for querying the data. Sche...

Differences Between Hibernate and Spring Data JPA?

Differences Between Hibernate and Spring Data JPA? In this quick article, I would like to describe what is the difference between  Hibernate ORM framework  and  Spring Data JPA . Let's first know the definition of  JPA ,  Hibernate , and  Spring Data JPA , so this will make it easy to discuss the difference between Hibernate and Spring Data JPA. What Is Java Persistence API? The Java Persistence API provides a specification for persisting, reading, and managing data from your Java object to relational tables in the database. Read more about JPA at  JPA Tutorial - Java Persistence API  (you will learn everything about JPA here). What Is Hibernate Framework? Hibernate is an object-relational mapping solution for Java environments. Object-relational mapping or ORM is the programming technique to map application domain model objects to the relational database tables. Hibernate is a Java-based ORM tool that provides a framework for ma...

Data Engineering - Tools & Intro

Data Engineering - Tools & Intro So I just realized that I am here after a month or so. I was busy at work and traveling. I am starting a kind of new series, I say it Data Engineering Series in which I will be discussing different tools. Of course, I am not able to discuss the entire concept of Data Engineering neither I know it as I will be learning myself. What is Data Engineering? Data Engineering is all about developing, maintaining systems that are responsible for transferring data in large volumes and make it available for analysts and data scientists to use it for analyzing and data modeling. Data engineering is a superset of Data Science or the subset, not clear to me but the collaboration of data engineers and scientists fruits useful data-driven solutions. Data Engineering tools It consists of several tools. Some are dealing with data storage while others with analysis and ETL. Ofcourse, Apache Kafka is one of them. The others tools that I might be covering are Apache...