learning-it by example

#308 Forward deployed engineer interviews 5.8 min

Two Systems Edit One Record: Lost Updates Explained

In a simulation, last write wins silently lost 340 of 1,000 edits. Two other ways lost none.

1. What is the lost update problem when two systems edit the same record?
2. In the simulation of an app and an ERP editing one customer record over 500 rounds (1,000 edits), what did the three ways of writing back lose and flag?
3. How does a version check stop a lost update?
4. What does the video call it when both systems change the same field of one record, and how is it counted?
5. Why is the 340 lost updates figure for last write wins, from the 500-round record simulation, not a guarantee for real systems?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Read the table

    Copy the code folder first. Run python run.py. For each of the three strategies, write down in your own words what the lost, flagged and retries numbers mean. You should see 340 lost for last write wins, and 160 flagged for the field merge and the version check.

    A hint

    Lost means a change to a different field that is missing afterwards.

  2. Fewer rounds

    In rounds.py change count=500 to count=100 in the rounds function. Predict roughly how the lost, flagged and retries numbers will change, then run python run.py. With this change last write wins loses 66, the flagged count is 34 and the retries are 100. The heading line still says 500 rounds, because that text is typed by hand. When you have finished, change count=100 back to count=500.

    A hint

    The version check retries once per round.

  3. Change the random seed

    In rounds.py change seed=7 to seed=1 and run python run.py. With this change last write wins loses 337 and 163 are flagged. Compare this with the 340 and 160 from before. What does that tell you about how much to trust a single number from a simulation? Then change seed=1 back to seed=7, because the next exercise needs it.

    A hint

    The video says seeds 1 to 10 gave a range of lost updates.

  4. Fewer fields to edit

    In rounds.py change FIELDS so it holds only phone and address. Predict whether last write wins will lose more or fewer updates, and whether more or fewer rounds are flagged. Then run python run.py. With this change last write wins loses 249 and 251 rounds are flagged. Write one sentence on why. Then put FIELDS back to phone, address and credit_limit.

    A hint

    With fewer fields, the two systems pick the same field more often.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

A simulation in one process with a fixed seed (seeds 1 to 10 gave 314 to 347 lost). Every round is a perfect collision, so last write wins loses one edit whenever the two fields differ. The version check's rejection and re-read are counted, not carried out. The ERP value winning a same-field conflict is my choice. Field merge is my own illustration.

Up next in Forward deployed engineer interviews

More in Forward deployed engineer interviews

All Forward deployed engineer interviews videos

Related videos