Hacker News new | ask | show | jobs
by XorNot 1520 days ago
Still winds up just feeling like a trick question: because the immediate response in any real world scenario is "why does the client need this feature?" when a CAS operation is right there.

But probably not what the interviewer wants to hear - maybe.

2 comments

Aside from being a lot simpler to use, a dedicated "multiply" command could end up being dramatically more efficient.

If multiple clients are simultaneously trying to update the same value, then locking allows them to take turns with relatively little overhead. With compare-and-set, all but one of the clients would fail at the "compare" step and need to retry, requiring additional network round-trips.

That’s not or shouldn’t be a trick question! “An affordance for what I’m asked to do already exists” is an excellent answer. Probably the best answer in most scenarios, and the one I’d most hope/expect to encounter from a “senior”.