Saurav Singh
1 min readJul 9, 2019

--

Michael Pogrebinsky Thanks for reading my post.
If server first performs the operation and then crashes right before it updates the idempotent key storage, it should rollback the entire transaction and return error to the client so client can try again safely. By doing this it will guarantee atomicity.

Example.
function execute(parms, idempotentKey) {
return new Promise(async (resolve, reject) => {
const dbConn = await dbConnection();
try {
await dbConn.beginTransaction();
await dbConn.execute(query);
await redisClient.setAsync(idempotentKey, response);
await redisClient.expireAsync(idempotentKey, process.env.KEY_EXPIRE_TIME)
await dbConn.commit();
return resolve(response)
} catch (error) {
await dbConn.rollback();
return reject(new Error());
}
});
}

--

--