Posts, likes and friends work the same way in both models
Every write is local to its writer; a delete marker and a cleanup worker keep links right.
Ana posts and Ben likes: every write is local to its writer
Ana's post has one owner: Ana. Ben's like has one owner: Ben. So both are shared rows, in both models.
Press play and watch where Ben's like is written:
1/3US West checks its copy of the post, then writes Ben's like. About 0.3 ms.
Ben never waits for an ocean. His write lands at home, and the copy travels behind him.
A comment works the same way. The comment is Ben's row, written in US West.
Ana deletes the post: a marker travels and workers clean up
Ben's like points at Ana's post across 2 regions. That is a weak ref. So the delete uses the 5 parts.
Watch the marker leave Singapore and the worker act in US West:
1/4One transaction in Singapore removes the post and writes the delete marker.
In the test the post was clean in all 3 regions after 197 ms. Measured, simulated distance Of 200 likes that raced a delete, none stayed. Measured, simulated distance
The like counter is the one social place where the models could differ
A counter is one number that many people change. Read literally, the 3-place rule sends it to the global database.
That would make every like from Singapore wait 187 ms. A like is the cheapest tap in the app. It should not cross an ocean.
The better way works in both models. Each region counts the like rows it already holds as copies.
| Way to count likes | Wait for the person who likes | Problem |
|---|---|---|
| One counter row in the global database | Up to 187 ms | Slow tap; many people fight over one row |
| Count the copied like rows in each region | 0.3 ms | The count can lag by 0.1 seconds |
Counting copies wins. This is guard rule 2 at work: a like has one owner, so it stays shared. Not tested
A friendship is two own rows, one written by each person
Ben asks Ana to be friends. Nobody else writes to that friendship. So no global row is needed.
The steps are the same in both models:
- Ben asksUS West writes Ben's request row. Ana sees the copy about 90 ms later.
- Ana acceptsSingapore writes Ana's friend row. US West sees the copy and writes Ben's friend row.
- Ben unfriendsUS West deletes Ben's row and writes a delete marker. Singapore's worker removes Ana's row.
- Friends againA new request starts at step 1, even while the old marker still exists.
Each step is one local transaction. The link between the 2 rows is a weak ref.
The tests found one real fault here. A request sent in the first 0.1 seconds after an unfriend was lost, in 25 of 50 tries. Measured, simulated distance
The fix is small. The app answers "already friends" until the old row is gone. The caller then asks again. After the fix, 100 of 100 tries ended as friends. Measured, simulated distance