Distributed Systems

Backend Fundamentals · 16 lessons

  1. Distributed consensus — Imagine a group of friends trying to pick a meeting time. Each friend proposes a time, and they vote. The friend with the majority becomes the leader who announces the final time…
  2. Leader election — Motivation In a distributed system you often have many identical service instances that can perform the same work. When a task must be performed once (e.g., a cron job, a cleanup…
  3. Distributed locks — Motivation In a distributed system, many processes or services may try to modify the same resource (a row in a database, a file, a cache entry, etc.) at the same time. Without…
  4. Distributed transactions — If any friend says “no” at any step, the whole plan is aborted. This is similar to a two‑phase commit (2PC): a prepare phase where all participants agree, followed by a commit…
  5. Two‑phase commit — When a business operation touches multiple independent data stores (e.g., a PostgreSQL order table and a Redis inventory cache), we want the whole operation to either succeed…
  6. Saga pattern — Motivation In a distributed system, a single business transaction often touches many micro‑services or databases. Traditional ACID transactions guarantee atomicity only within a…
  7. Eventual consistency — Motivation In a distributed system, data is often replicated across multiple nodes (databases, caches, micro‑services). When a client updates data, that update must be propagated…
  8. Strong Consistency — In a distributed backend, data is often replicated across multiple nodes or services. When a client writes a value, that write must be visible to all subsequent reads, no matter…
  9. Vector clocks — Why it matters When you build multi‑master databases, CRDT‑based collaboration tools, or event‑sourced services that run on multiple replicas, you need a lightweight mechanism to…
  10. Logical clocks — Imagine each node is a book that writes its own page numbers. When you read a page, you can tell if it was written before or after another page by comparing numbers, even if the…
  11. Network Partitions — Motivation In a distributed system, nodes communicate over a network that can become unreliable. A network partition happens when a subset of nodes can no longer reach another…
  12. Split brain — In a distributed system, multiple nodes cooperate to provide a single logical service (e.g., a database cluster, a cache cluster, or a microservice that needs high availability)…
  13. Clock Synchronization — If you ignore clock synchronization, you risk subtle bugs that surface only under load or after a few hours of operation. In production, this can lead to data loss, security…
  14. Gossip protocols — Motivation In a distributed system you often need to keep many nodes in sync – e.g., a cluster of cache servers, a set of micro‑services that share a feature flag, or a group of…
  15. Quorum — Motivation In a distributed system you often have multiple replicas of data or services. When a client asks for a value or performs an update, you need a single, consistent answer…
  16. Replication strategies — Analogy: Think of a library that keeps a copy of every book in three branches. If one branch closes, the other two still have the books. Readers can go to any branch, and the…