When I handle concurrent request on Node.js,
// before two req,
// userpoint : 1000
// using point amount per req, 1000
router.post('/', async (req) => {
const willUsingPointAmount = req.body.amount;
const userPoints = await getUserPoints();
if (userPoints >= req.body.amount) {
res.send(await usingPoint());
}
})
When concurrent req incomes,
I think Event Queue described like [(req1)getUserPoints, (req2)getUserPoint, (req1)usingPoint, (req2)usingPoint].
So both usingPoint was called in this situation.
Is there any solution better than database transaction?