Architecture Expert
Eventual Consistency in Practice¶
Eventual ConsistencyDistributedCAP 3 min read
What is eventual consistency and how to work with it in UI and backend.
Principle¶
After a write operation, data doesn’t have to be immediately consistent across all nodes. But eventually, it will sync up.
UI Approach¶
// Optimistic UI update
async function createOrder(data) {
dispatch({ type: 'ORDER_CREATED_OPTIMISTIC', order: data });
showToast('Processing...');
const result = await api.createOrder(data);
dispatch({ type: 'ORDER_CONFIRMED', order: result });
}
Examples¶
- Twitter — tweets don’t show up for everyone at the same moment
- E-commerce — stock count can be inaccurate for a while
- DNS — changes propagate over hours
Summary¶
Eventual consistency is the reality of distributed systems. Design UI and processes to work with it naturally.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.