Reputation: 65
I am developing a game where 2 players are matched against each other using AWS API Gateway Websockets.
Both players submit their moves and update a table in my database. How can I know that I received the two moves, so I can notify both sockets that the round finished?
Now I tried this:
But this approach fails if they submit their moves at the same time, as both reads would give no results.
My DB design is:
primaryKey: 1$
secondaryKey: user1
moves: [move1, move2, move3...]
primaryKey: 1$
secondaryKey: user2
moves: [move1, move2, move3...]
(I have 2 records for each game because I need to be able to query games based on users too, which helps with the statistics and other functionalities of the game)
As a temporary solution, I am using DynamoDB Streams to invoke a lambda every time users submit their moves, and if I have 2 moves, I send through their sockets what I need to send. However, I think that using Streams is only for logging purposes, and not business logic.
Upvotes: 1
Views: 62
Reputation: 19693
Streams is not intended for just logging purpose and is very much used for business logic especially when coupled with Lambda as it provides a cost efficient mechanism for event driven architectures.
I would continue to use Streams as it suits your needs and is exactly what they are intended for.
Upvotes: 2