Unless the data isn't that important, it's better to use an RDBMS with SSI[1] support, and retry or bail out if there's a concurrent write.
http://www.postgresql.org/docs/current/static/mvcc-intro.htm...