How do we avoid cases where losing an ACK could lead to users doing an action multiple times (e.g. pressing the like button)? Idempotence!
is idempotent if
For example
- Not idempotent:
- Idempotent:
Idempotent requests can be retried without deduplication.
However, this isn’t perfect when there are other actors/actions that intermix. For example, but (e.g. liking, unliking, then liking is not the same as unliking!)
To somewhat fix this, use tombstones and record logical timestamp for when events happen
- Then, we can reconcile replicas by propagating the record with the latest timestamp and discard the records with earlier timestamps
- Then, to fix concurrent writes by different clients
- Last writer wins (LWW): resolve conflicts using a logical clock that gives total ordering (e.g. Lamport clock)
- Multi-value register (give all options to let user/algorithm above resolve it): use a Vector clock, replaces if ; preserve both if