Synchronizing Events Between Two NATS Clusters with JetStream

20 views
Skip to first unread message

musa burak erdihan

unread,
Jan 29, 2025, 10:24:31 AMJan 29
to nats

I am using a microservices architecture with event sourcing and leveraging NATS as the communication layer.

When a new event is generated, I send it to the event bus via JetStream, allowing relevant services to consume it. The JetStream instance is configured with Interest Retention. Microservices use a separate mechanism for projections at startup, which I will not cover here.

I have two clusters in different locations, currently operating in an active-passive setup. I need to ensure that events produced in Location-1 are also delivered to Location-2.

I do not want to modify the existing JetStream configuration. However, I can introduce a separate NATS cluster, JetStream instance, or service to handle synchronization.

Desired Scenario:
  • Inter-location communication can experience interruptions.
  • When an event is produced in Location-1, it should be stored in a JetStream instance in Location-1.
  • This JetStream instance should automatically replicate the event to the JetStream instance in Location-2.
  • Once a service in Location-2 consumes the event and sends an acknowledgment, the event should be removed from both JetStream instances.
  • This setup ensures that if the connection is lost, synchronization resumes once it is restored.

I have looked into solutions like Leafnode, accounts, and JetStream domains, but I’m unsure if these approaches would fully support this scenario or how I should implement it.

What would be the best approach to achieve this synchronization while ensuring reliability?

Reply all
Reply to author
Forward
0 new messages