36 votes
Accepted

Microservices: Handling eventual consistency

Based on what I've understood about eventual consistency, all these services (consumers) will receive the event at the same time and process them separately which, in a good scenario, will lead to ...
  • 11.9k
19 votes
Accepted

How do I write tests against an eventually consistent service?

Consider non-functional requirements when designing your functional tests -- if your service has a non-functional requirement of "Consistent within x (seconds/minutes/etc)", simply run the PUT ...
16 votes

Rehydrating Aggregates from a "snapshots" projection rather than the Event Store

What I'm not super clear on is why you would ever rehydrate your Aggregates from the Event Store itself. Because the "events" are the book of record. If projecting changes to "read" databases is ...
15 votes

What is eventual consistency?

What is "eventual consistency"? How does it compare to "transactional consistency"? When does it happen? Consistency models describe how a system (nominally a distributed system) responds to change. ...
  • 5,180
15 votes

DDD: Why is it a bad practice to update multiple aggregate roots per transaction?

What makes updating multiple Aggregate Roots in one request/transaction such a bad practice? The problem is the other way around - trying to modify multiple aggregates in a single transaction is an ...
15 votes
Accepted

DDD: Why is it a bad practice to update multiple aggregate roots per transaction?

From everything I've read, here and elsewhere, the reason seems to be that changing multiple aggregates in one transaction creates the requirement that they are stored on the same database host. (Let'...
  • 372
11 votes

How to handle transactional operations in an event-driven architecture?

In my experience, most questions about transactionability and microservices are caused by the following two reasons: The transactional data is placed in different microservices: This is wrong by ...
9 votes

Microservices: Handling eventual consistency

In your case you cannot just process all three things at once. What you need is a process. Here is an extremely simplified example: It is important to know that state altering operations MUST be ...
  • 9,955
8 votes

How do I write tests against an eventually consistent service?

You really want your tests to be fast and consistent. If you start creating tests that may occasionally fail due to eventual consistency, you'll ignore the test when it fails, and then what use is it? ...
8 votes

How do I write tests against an eventually consistent service?

OK, so. "What Are You Testing" is the key question. I am testing my internal logic of what happens assuming the google stuff works In this case you should mock the google services and always return ...
  • 65.4k
8 votes

Be sure to send email only once

But in this case after email is sent someone may turn off server and then that information will not be stored in DB. This is not something you can 100% cover in code. It's always possible that the ...
  • 38.7k
7 votes

How do I write tests against an eventually consistent service?

Use one of the following: After PUT, retry GET N times until success. Fail if no success after N tries. Sleep between PUT and GET Unfortunately, you have to pick magic values (N or sleep duration) ...
6 votes

Patterns for maintaining consistency in a distributed, event sourced system?

In a traditional N server <-> 1 RDBMS style system, the database is used as a central point of synchronisation which helps prevent such inconsistencies. In event sourced systems, the "event store" ...
6 votes

Rehydrating Aggregates from a "snapshots" projection rather than the Event Store

Since you don't specify what would the purpose of the "write" database would be, I will assume here that what you mean is this: when registering a new update to an aggregate, instead of rebuilding the ...
6 votes

DDD: deciding when to lean towards eventual vs transactional consistency

It seems you are overthinking this. The advice is illustrated in a few different and related use cases. 1. User Submits Proposal: Use case where the user is responsible for ensuring Proposal is ...
  • 61
6 votes

What are the problems with command handlers returning data in CQRS?

CQRS is a principle, not a dogma. Like all principles, it has its positive and negative aspects in its own right. Departing from "pure CQRS" could just mean that you can't meaningfully ...
6 votes
Accepted

How is cross device eventual consistency achieved in real time?

Different distributed systems try to achieve different consistency models. Eventual consistency is an extremely weak model that just says that eventually, all nodes will agree on a common state. It ...
  • 126k
5 votes
Accepted

Event Sourcing , sagas, bus and eventual consistency

Event storage Event storage will depend on your application but it is a lot easier if you use a flexible storage for your events (so a NoSQL DB, JSON or XML). How you deal with updates will depend on ...
  • 6,242
5 votes

How to to send a file and record that it has been sent in an atomic way?

I don't think this is about atomic-operation, synchronization, asynchronous-programming, or transactions. I think this is about meaningful state. Right now you have three possible states. The object'...
5 votes
Accepted

Is the C in ACID is not the C in CAP?

The meanings are slightly different I think. In short: Consistency in ACID means that no dataset may be an invalid state or represents data which are semantically invalid after a transaction is ...
  • 249
5 votes
Accepted

DDD - Domain events vs application events

I'm considering two types of notifications For a number of reasons, the literature is pretty weak here; but I believe that you will find that the taxonomy of "domain events" and "integration events" ...
5 votes
Accepted

CQRS - How can a command properly validate when queries are required?

How can I avoid and protect the command from the concurrency case exposed before? The only way to "protect" yourself against concurrent changes is to hold a lock, which effectively means to have both ...
5 votes
Accepted

In which database CQRS Command performs a Query?

If I need to take the customer info I need to read from the Write Database? It's a correct way? Short answer: yes. But you're missing a few steps in your reasoning. Commands and queries are ...
  • 38.7k
5 votes

Communication between services in a microservices architecture, is direct communication okay?

You mix a couple of things here, let's go in order: 1. "Event sourcing" is not a competing thing to "REST Endpoints", they have absolutely nothing to do with each other. "...
4 votes

Microservices: Handling eventual consistency

What you're facing here is the two generals problem. In essence: how can you be sure a message is received and a response to that message occurs? In many cases, a perfect solution does not exist. In ...
4 votes

User interface and process that involves asynchronous communication between several microservices

First thought: make the implicit explicit. The traveler is offering your an opportunity to derive business value; your absolute top priority at that point is to capture that opportunity -- everything ...
4 votes

DDD - Domain events vs application events

After watching the Udi Dahan's video, I'm trying the following approach: I have an event store that contains the domain events, And I have an achievement store that contains what has been ...
4 votes

How does a distributed system both tolerate network partition and achieve consistency?

The CAP Theorem says that you can only achieve at maximum two out of the three properties of Consistency (every read receives the most recent write or an error), Availability (every read receives a ...
4 votes

How to handle data inconsistency in microservice architecture?

I believe there's three typical ways you could handle this: Guarantee delivery of your messages Run a reconciliation process Switch to a pulled events approach A little detail on each approach... ...
4 votes

Why is it considered hard to maintain strong consistency in a distributed system?

Retries aren’t guaranteed to succeed. And while your system is retrying, it isn’t available. For just reads, that is only a small problem. What happens when writes fail? “Just retry” doesn’t work ...
  • 107k

Only top scored, non community-wiki answers of a minimum length are eligible