educative.io

Educative

Need a 4-byte number to lock each user’s record

If we assume that we would need a 4-byte number to lock each user’s record to resolve our atomicity problems, we would require a total 36MB memory.

why does the lock require 4 bytes per row? do we need the storage even if the lock is not being used?

I am not sure about this, but I think each row represent a unique user, and the worst case scenario is at the same time all the users are hitting the API, that’s why in this scenario we assume we need an integer (4 byte) per user to lock the database transaction to made sure of atomicity.