3 ms·
> 1. you need to use a Pub/Sub implementation that does support exactly-once delivery (only MySQL/PostgreSQL for now), To implement exactly-once delivery you f
by kevincox 6y ago
> 1. you need to use a Pub/Sub implementation that does support exactly-once delivery (only MySQL/PostgreSQL for now),
To implement exactly-once delivery you first need exactly once delivery.
But this project doesn't implement exactly once delivery.
> It can be triggered by calling the http://localhost:8080/count/{counterUUID} http://localhost:8080/count/{counterUUID} endpoint.
Oh, but what if my network goes down right after I sent that request? Did it succeed? There is no way of knowing. So now I have to pick between sending again (at least once) or not (at most once).
You can get exactly once delivery. But you need to involve request IDs which you haven't done here. Imagine something like this:
PUT http://localhost:8080/count/{counterUUID}?request-id={requestUUID}.
The requestUUID must be unique per counter. It should be generated when the action occurred (like when the user clicks a button) and should be reused for retries. (Of course this will still be foiled by a user clicking a button multiple times)
Now the server does:
INSERT INTO increments(counter_id, request_id, counted)
VALUES (:counterUUID, :requestUUID, FALSE)
ON CONFLICT DO NOTHING
Now instead of deleting the record you just mark `counted = TRUE`.
In theory you can never delete records from this table. In practice you can add a timeout after which double-counting is acceptable.
- roblaszczak 6y agoExactly-once delivery is covering processing in this scenario. Because of that it is not covered in tests and schemas. REST endpoint was just added to create entire use case. But you are right, if in this part of the system something will go wrong you will have duplicate message. But it’s rather at least once publish rather at least once delivery. Message will be delivered once, but published twice :)
- kevincox 6y agoBut that seems pointless. Exactly-once covering a subset of the pipeline doesn't guarantee exactly-once. At best it improves your chance of exactly-once delivery. If you really need exactly-once delivery you need to make it end-to-end. If you don't support end-to-end exactly-once than you are really just an at-least-once delivery system. So you are making a guarantee that provides little if any benefits because it can not be tied into the whole pipeline.