Understanding Eventual Consistency in Distributed Systems

Example scenarios:

Let’s consider a social media application where you can “like” posts. Suppose a post currently has 100 likes. When you click the like button:

  1. Immediate Response: The UI immediately shows the like (optimistic UI update), so you see 101 likes right away to provide a good user experience.
  2. Write Operation: The like is written to the nearest database replica, which now records 101 likes for this post.
  3. Asynchronous Propagation: This change (from 100 to 101 likes) is then propagated to other database replicas across different regions.
  4. Temporary Inconsistency: During propagation, different users might see different like counts—some may still see 100 likes while others see 101 likes.
  5. Eventually Consistent: In this case, the system is eventually consistent because, after a few seconds (or milliseconds), all replicas sync up, and every user sees 101 likes.