Microservice Patterns | Design Patterns | Synchronized Cross-Instance Events


Microservice and Containerization Patterns > State & Data Access Patterns > Synchronized Cross-Instance Events
Home > Design Patterns > Synchronized Cross-Instance Events

Synchronized Cross-Instance Events (Erl, Naserpour)

How can microservice data consistency be achieved across all microservice instances when each microservice instance has its own database instance?

Synchronized Cross-Instance Events

Problem

When microservices spawn multiple runtime instances, there is certain data that needs to be kept in sync across these instances to avoid the service data or state from becoming invalid and unable to fulfill service requests.

Solution

A system can be implemented that notifies each microservice instance of the relevant events and changes they need to be aware of without creating dependencies between themselves.

Application

An event publishing and subscribe/notification method is implemented to ensure that certain events are registered and subscribed to by instances, and that the subscriber instance is notified when specific subscribed events are triggered or registered.

A system is introduced to ensure that each microservice instance publishes an event whenever it occurs and that the database instances of the microservice instances subscribed to that event are updated.

Synchronized Cross-Instance Events: Microservice A (Instance 1) was subscribed to Microservice B (Instance 2) and is therefore notified of the change to Database B (Instance 2). Upon receiving the notification, Microservice A (Instance 1) correspondingly updates Database A (Instance 1). 

Microservice A (Instance 1) was subscribed to Microservice B (Instance 2) and is therefore notified of the change to Database B (Instance 2). Upon receiving the notification, Microservice A (Instance 1) correspondingly updates Database A (Instance 1).

This pattern is applied by identifying events designing function for subscribing to specific state changes, as explained in the complete pattern description.

Module 10: Advanced Microservice Architecture & Containerization.

This pattern is covered in Module 10: Advanced Microservice Architecture & Containerization..

For more information regarding microservice and containerization courses and accreditation,
visit the Microservice Architect Certification program page..