Skip to main content

Distributed Locking, Idempotent Consumers, Duplicate Messages and Event Ordering

Learn Distributed Locking, Idempotent Consumers, Duplicate Messages and Event Ordering (Phase 9 · Distributed Systems (Core), Microservices) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Distributed locking • A distributed lock gives mutual exclusion across instances (only one instance runs a job, updates a shared resource). Implementations: database (row lock SELECT ... FOR UPDATE , advisory locks, unique-row "lock table"), Redis ( SET key value NX PX ttl ; Redisson RLock ; Redlock is debated), ZooKeeper/etcd/Consul (ephemeral nodes/leases: stronger), ShedLock for scheduled jobs (DB/Redis-backed). • Pitfalls: locks must expire (TTL) or a crashed holder blocks everyone; a paused holder (GC, network) can resume after expiry and corrupt data: use fencing tokens (monotonic token...

More lessons in Phase 9 · Distributed Systems (Core)