Chapter 63. Be Prepared to Repeat
Ricardo Miranda
My first car had a remote with a single button to lock/unlock the doors. The car behaved as a finite state machine: if the doors were locked, pressing the remote’s button would unlock them; the next time, the doors would lock again. This was really annoying. How I wished the remote had distinct lock and unlock buttons!
According to Wikipedia, “Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.”
In the cloud, systems tend to be decoupled, with components communicating among themselves via asynchronous message passing. Eventually, duplicate messages appear, either intentionally or unintentionally. By preparing for idempotency we can avoid costly refactoring.
Strategies to Cope with Duplicate Messages
Strategies to deal with duplicates vary in several dimensions. The first thing to consider is how expensive it is to compute more than once. Making services aware of which messages were already processed creates an overhead that should never be underestimated.
Often it is easier to just repeat operations. This is a big leap from the monolith (a single large application)—a leap fundamental to becoming a cloud engineer.
Stateless Consumers
Stateless consumers are servers ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access