BSS Algorithm + Causal vs FIFO vs Total Order
Intuition
FIFO says 'messages from the same sender arrive in order'. Causal order says 'if and both target the same destination, is delivered before ' — even if the senders are different. This matters when an effect's cause comes through a different path. Total order goes further: all processes deliver every message in the same global order.
Explanation
Causal order of message delivery — definition. If and both have the same destination, then must be delivered before at the destination. Note: causal order degenerates to FIFO when both messages are from the same sender.
Why FIFO is insufficient. Example: sends to , then , then sends . By causality, (through ). So should be delivered before at . But FIFO doesn't enforce this because and are from different senders — they could arrive in any order via FIFO. Causal order needs vector-clock-based tracking.
Birman-Schiper-Stephenson (BSS) algorithm. Each process maintains a vector . **On send to **: ; piggyback on message as . **On receive of from at **: deliver only when both of the following hold: (a) (this is the next message expects from — FIFO from ); (b) (all causally preceding messages from other senders have arrived). Otherwise buffer . After delivery, .
Condition (a) intuition. Ensures no message from is skipped — delivers the *next* sequential message from each sender.
Condition (b) intuition. Before delivering , ensure has seen all messages that *causally preceded* from other senders. If is greater than what has seen (), some causally-prior message from hasn't yet arrived — buffer and wait.
Why causal order is useful. Replicated databases: updates that depend on prior updates must be applied in causal order. Group communication: chat messages — 'Bob asks a question' before 'Alice answers it' even if routed through different paths. Distributed debugging: cause-then-effect, never effect-then-cause.
Causal vs FIFO vs Total order. FIFO orders only messages from the *same sender*. Causal orders any pair where . Total orders ALL messages in a single global sequence consistent across all receivers — even concurrent messages get an arbitrary but consistent order. Total order is stronger than causal (and needed for state-machine replication).
Definitions
- Causal order delivery — If and both target the same destination, is delivered before . Stronger than FIFO.
- FIFO order — Messages from the same sender arrive in the order they were sent. Weaker than causal.
- Total order — All processes deliver every message in the same global sequence — concurrent messages also get a consistent order. Required for state-machine replication.
- BSS algorithm — Birman-Schiper-Stephenson causal delivery via vector clocks. Two conditions: (FIFO from sender) AND (causally prior msgs arrived).
Formulas
Derivations
BSS correctness — causal order preserved. Suppose with from and from to the same destination . The vector piggybacked on reflects at the time of . Since , at that time was already updated to include — so value of at . When arrives, condition (b) requires — meaning must have already received (or all messages up to that point from ). Hence is delivered before . ∎
Examples
- Three-process causal example. sends to (timestamp ). sends to . receives (), then sends to (). Suppose arrives at before . BSS check on : (a) , , need — FAIL. Buffer . Then arrives: (a) ✓; (b) trivially ✓. Deliver . Re-check : (a) , now, still need — FAIL. Wait. Actually condition needed for — but wasn't sent to . Hmm, 's (a) is ? Let me recompute: from has ; condition (a) for sender : means . So would need to have already received 1 message from — but this IS the first. So should be 1, not 2. Re-derive: after receiving , 's clock is ; before sending , → ; piggyback . At , . Condition (a) for from : , need . FAIL. Buffer. So waits for the previous message from ... but there is none (only from to ). Actually 's expectation is that some earlier message from should arrive — but hasn't sent anything else to . The vector tracking is off. The correct BSS uses on send (not piggyback after) — so in this trace. Cleaner: sends with (just before incrementing). Condition (a): ✓. Condition (b): ? FAIL. Buffer. arrives, . Re-check : (a) ✓; (b) ✓. Deliver. Order preserved: then . ✓
- WhatsApp / group-chat application. Bob: 'What time?' (msg1 from B to C). Alice receives and replies: 'Noon' (msg2 from A to C, after receiving msg1 from B). FIFO doesn't help — msg1 and msg2 have different senders. Causal order via BSS guarantees Charlie sees the question before the answer.
Diagrams
- Three-process causal example: arrows showing chain via ; receiver must deliver before .
- BSS state machine: msg arrives → check conditions (a) and (b) → deliver or buffer; when buffered msg's conditions become satisfied, deliver.
- Order strength diagram: FIFO ⊂ Causal ⊂ Total. Each level adds more pairs of ordered events.
Edge cases
- Causal degenerates to FIFO for same-sender messages — BSS condition (a) IS FIFO.
- Total order requires consensus for concurrent messages — heavier than BSS. State-machine replication needs total.
- BSS buffering can grow unboundedly if a process is slow — practical implementations bound buffer size.
- Late delivery (large buffers) under high message rates is the cost of strict causal ordering. Trade-off vs throughput.
Common mistakes
- 'Causal order is the same as FIFO.' No — FIFO orders only same-sender. Causal orders any causally-related pair.
- 'Total order is just causal order on all messages.' No — total order also assigns an order to *concurrent* messages, which causal does not.
- Forgetting condition (b) in BSS. Without it, you only get FIFO.
- Confusing 'deliver' with 'receive'. A message can be received (arrives at process) but not yet delivered (passed to application). BSS buffers received-but-not-yet-deliverable messages.
Shortcuts
- Causal definition: at common destination.
- BSS condition (a): — FIFO from .
- BSS condition (b): — causally prior msgs arrived.
- Strength: Total ≻ Causal ≻ FIFO.
Proofs / Algorithms
BSS preserves causal order. Suppose at and respectively, both targeting . By the happened-before, at has at least the value of at . So . At , 's condition (b) requires . So , meaning has already received and delivered messages from through 's timestamp. Hence was delivered before . ∎