Does DynamoDB have a mechanism to lock a row for reading?

Viewed 5002

Does Amazon DynamoDB have a mechanism to lock a row for reading? Something similar to what's described for PostgresQL at https://www.2ndquadrant.com/en/blog/what-is-select-skip-locked-for-in-postgresql-9-5/

I could not find any documentation, hence wanted to confirm.

EDIT: I want to lock a row so that "reads" do not get this row while it is locked. It is available for reading again when the lock is released.

EDIT2: Purpose is to emulate a queue for distributed processing. Different clients need to pull an item from a table for processing. See the above link to get an idea of how this is achieved in PostgresQL.

1 Answers

DynamoDB does not support this.

RDMBSs associate row locks with a transaction and associate transactions with a single client connection to the database (and automatically releasing those locks if the connection holdng them goes away) but DynamoDB is connectionless -- everything between your code and the database happens over a series of uncorrelated HTTPS requests. (And, of course, DynamoDB also isn't an RDBMS).

DynamoDB thus has no concept like SELECT ... FOR UPDATE (which locks the found rows and prevents other transactions from seeing them, either by implicit read-blocking or explicit row skipping) and has none of the capabilities that would follow from that.

The closest thing -- which admittedly is not particularly close -- would be using consistent reads and conditional writes (which allow updating an attribute only if it already matches an expected state) to check, set, and clear a user-defined locking attribute that flags the state of each record and perhaps leaves a trail of how the record came to be in that state (populated, e.g., with something like "record locked at timestamp w by thread x from pid y on host z," helpful when figuring out what happened if records get stuck in the locked state).

Related