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...

Machine Learning & Deep Learning

Machine Learning & Deep Learning Understanding the latest advancements in artificial intelligence can seem overwhelming, but it really boils down to two concepts you’ve likely heard of before:  machine learning  and  deep learning . These terms are often thrown around in ways that can make them seem like interchangeable buzzwords, hence why it’s important to understand the differences. And those differences should be known! Examples of machine learning and deep learning are everywhere. It’s how Netflix knows which show you’ll want to watch next or how Facebook knows whose face is in a photo. And it’s how a customer service representative will know if you’ll be satisfied with their support before you even take a customer satisfaction (CSAT) survey. So what are these concepts that dominate the conversations about artificial intelligence and how exactly are they different? What is machine learning? Here’s a basic definition of machine learn...

Creating REST API With Spring Boot

Let's Create a REST API With Spring Boot In this post, we will learn how to create REST API with Spring Boot, JPA, Hibernate, and MySQL. Create the Spring Boot Project. Define Database configurations. Create an Entity Class. Create JPA Data Repository layer. Create Rest Controllers and map API requests. Create Unit Testing for API requests and run the unit testing. Build and run the Project. Requirement We need to create a simple REST API to store user data to MySQL database with that API so we can create, update, delete, and get users information. Create the Spring Boot Project First, go to  Spring Initializr  and create a project with below settings Web  — Full-stack web development with Tomcat and Spring MVC DevTools  — Spring Boot Development Tools JPA  — Java Persistence API including spring-data-JPA, spring-orm, and Hibernate MySQL  — MySQL JDBC driver Actuator  — Production-ready features to help you monitor...