Timeouts are chosen with typical and worst cases in mind
Failures
Partial Failure
Some parts work while others fail
A silent machine may be crashed, busy or unreachable
Timeouts are guesses, not facts
Wrong answers are harder than crashes
Failures
Network Partitions
The network splits machines into groups
Each group may work fine inside
Rare on a good day, certain over time
Design for them from the start
[A] [B] X [C] [D]
group 1 cut group 2
Clocks
Time And Order
Every clock drifts
Timestamps cannot always order close events
Lamport (1978): order events by what could influence what
Logical clocks are counters carried in messages
Copies
Replication And Consistency
Replicas are copies kept on different machines
They survive failure and serve nearby users
Strong consistency: every reader sees the latest write
Weaker forms allow stale reads for a while
Brewer 2000, Gilbert and Lynch 2002
The CAP Theorem
C: every read sees the latest write
A: every request to a working machine gets an answer
P: the system continues despite dropped messages
During a partition, choose C or A
Applying CAP
CP Or AP: Choosing By Cost
CP: refuse some requests to stay correct
AP: keep answering, repair differences later
Bank balance leans CP
Social feed leans AP
Choice
During a partition
Good fit
CP
Refuse some requests
Balances, bookings
AP
Answer, maybe stale
Feeds, likes, carts
Simulation
Eventual Consistency In 12 Lines
Two replicas accept writes during a partition
A merge rule picks the final value
Last write wins is simple but can lose updates
a = {'v': 'red', 't': 1}
b = {'v': 'blue', 't': 2}
def merge(x, y):
return x if x['t'] >= y['t'] else y
winner = merge(a, b)
a, b = dict(winner), dict(winner)
print(a, b)
# both replicas now hold {'v': 'blue', 't': 2}
Summary
Recap
Messages can be late, lost, duplicated or reordered