Why Computers Can't Count Sometimes
Why Stack Overflow recommends it
Stack Overflow users link it when they need a simple, concrete illustration of race conditions and lost updates when several threads or users increment a shared counter.
Recommended by 3 people across 3 different months, 2018 to 2022.
What it is
Tom Scott explains why counters on sites like YouTube and Twitter jump around or lag, using threading, race conditions, eventual consistency and caching as the explanation. It is a short, accessible explainer with a computing-history museum as the backdrop.
What people said
Recommends Caleb H. · 2018-11 · Stack Overflow · on “Count like and unlike php”
So...what seems to be the problem? I must say, handling likes and unlikes can end up being problematic. Check out this YouTube video for a good explanation: [this video]
Recommends user2819245 · 2019-05 · Stack Overflow · on “Task.WaitAll seems bugged”
If the thing about race conditions is still a mystery to you, Tom Scott made a video a while ago where he (among other things) gave an example of possible race conditions when incrementing numbers concurrently that's simple to understand: [this video]
Recommends TheLizzard · 2022-09 · Stack Overflow · on “How to wait for a server response without freezing the tkinter GUI”
The GIL ensures that 2 threads can't write to a variable at the same time but doesn't ensure that each thread has the right value for the variable. In the example you linked, it is possible that python does `value = value + amount` instead of `value += amount`. Look at this [this video] video for an explanation. In my answer that shouldn't be a problem as only 1 thread writes to `flag[0]`.
Cites Krukas · 2019-06 · Stack Overflow · on “counting views sometimes work, sometimes not counting”
You could keep the function in your model, but you still need to call it from your Django view. Also updating your view count this will get incorrect counter if multiple people open the page at the same time ( [this video] )
Cites Noah · 2021-06 · Stack Overflow · on “Trigger a function after 5 API calls return (in a distributed context)”
The other answers suggesting Promises seem to assume all these requests necessarily come from the same client. If the context here is distributed systems, as you said it is, then I don't think those are valid answers. If they were, then the interview question would have nothing to do with distributed systems, except to essay your girlfriend's ability to recognize something that isn't really a distributed systems problem. And the question does have the shape of some classic problems in distributed systems. It sounds a lot like [this video] : How do you achieve qualities like atomicity and consistency [LINK] in a multi-threaded, multi-process, or multi-client environment? Failing to recognize this,