← Lessons

quiz vs the machine

Gold1430

System Design

The Document Sync Protocol

Bringing a freshly joined client up to date efficiently.

5 min read · core · beat Gold to climb

The sync goal

When a client connects, it must reach the same state as everyone else while sending the least data. A document sync protocol exchanges a compact summary of what each side already has, then transfers only the missing pieces.

State vectors

Many systems use a state vector, a small map from each replica id to the highest update counter it has seen. Two clients swap vectors, compute the difference, and each sends exactly the updates the other lacks.

Two step handshake

  • Step one sends my state vector so you can compute what I am missing.
  • Step two sends the missing updates plus my own vector so the exchange is symmetric.

This delta based approach scales far better than shipping the whole document, which matters when a user reopens a large file after a short absence.

Key idea

A sync protocol swaps state vectors to compute differences and ships only the missing updates rather than the full document.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a state vector record?

2. Why is delta based sync preferred over sending the whole document?