[openstreetmap/openstreetmap-website] Idempotency for API 0.6 (#2201)
notifications at github.com
Mon Apr 22 12:06:09 UTC 2019
Rather than require clients to send a token and have responsibility for checking this, would one approach, which I suspect would not require substantial changes to the server infrastructure be:
1. Whenever a POST comes in (for any API call), create some kind of hash of the incoming data, first omitting anything which is known to be different (e.g. the request time).
2. Store the hash in a global table of `requests(hash, response)` which is a table of incoming hashes and responses where each entry has a lifetime of say one day or a week (as users/clients are unlikely to retry after that).
3. When the server has processed the request and sends back the response set the `response` field to the response XML and continue the response to the client as normal.
4. If the server receives a repeated request that has the same hash, i.e. the client has just resent the same request, immediately send back the same response, without any further processing. For good practice, send an additional header stating that this is a cached response.
This would seem to me to require no changes to any client, and eliminate almost all duplications on the server, with the code change essentially just a global interception to any POST request by implementing that cache at that level.
This approach admittedly does not solve Andy's point:
> But that still doesn't work, since if the server receives a new trace, and then the owner changes the description 2 seconds later on the website, and the server receives the same creation request 2 seconds after that, it doesn't have enough information to know if it's an intentional recreation or just a resent request.
but I don't think that is actually solvable, because a changed description is by definition a change in the request and could constitute a deliberate and separate change to the data.
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rails-dev