|
|
|
|
|
by partisan
4076 days ago
|
|
I would have thought that the opposite would be true; by having an CQRS/event sourcing system with eventual consistency would allow you to avoid posting duplicates to your database: 1. The user submits X number of requests within a second.
2. The system puts the request in a command queue that synchronizes the commands by coupon code, for example.
3. The command is popped off the queue and an event is generated and saved saying the coupon was redeemed.
4. The next command is picked up and all events are applied before processing. At this point, the command is no longer valid so you reject and send an event saying that an attempt was made to redeem a redeemed coupon.
5. Do the same for subsequent requests. To me, this approach is safer and easier to reason about. You have a log of the fact that someone made the attempt so you can report on this. Not sure you get that benefit from a stored procedure and a transaction unless you build it in and then increase the running time of the open transaction. |
|