Skip to content

Conversation

@OpesanyaAdebayo
Copy link
Member

No description provided.

Comment on lines +172 to +181
const requestHash = hashArguments(sender_id, recipient_id, amount);

const redisCheckResult = await checkRedisHash(sender_id, requestHash);

if (!redisCheckResult.success) {
return {
success: false,
error: 'Duplicate transaction',
};
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uncoooloj this is where I used the implementation for #3.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seen it, what if transactions are just a few milli seconds apart?

That's my fear. The system won't be done with this IO so both will pass.

What do you think?

Copy link
Member Author

@OpesanyaAdebayo OpesanyaAdebayo Feb 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, @uncoooloj Redis also has implementations for transactions and optimistic locking.

I'll update it in the final version.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so quick question, what if there was a request throttling to one request per 10 ms for example? sounds like a lazy hack but that + a transaction has solves our problem no?

const addElement = promisify(client.sadd).bind(client);
const expireElement = promisify(client.expire).bind(client);

async function checkRedisHash(accountId, hash) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uncoooloj this is the implementation for #3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants