3 ms·
It's not worth making the distinction between idempotent and non-idempotent writes given the possibility of network partitions. Every write must be made idempot
by naasking 10y ago
It's not worth making the distinction between idempotent and non-idempotent writes given the possibility of network partitions. Every write must be made idempotent because all you can do is retry in this case. PUT is merely an optimization on idempotent POST requests, one that will become progressively rarer as HTTPS continues to spread.
POST requests can be made idempotent by binding the result of processing that request to a future, so every subsequent request simply returns the already computed result.
Impure reads are the default, and pure reads are designated by long-lived cache headers, ie. it's an impure read that lasts as long as the server responds.
So really you just need GET and POST, and server-side frameworks should make POST requests idempotent by embedding some notion of futures for side-effecting operations. See the Waterken server for the first development platform to really get this right.
- int_19h 10y agoAn insert cannot be idempotent by the very definition of the operation.
- joncrocks 10y agoIt can be as long as you have some kind of identity information associated with the request, and provided alongside any requests that are the 'same'. e.g. Instead of saying "Insert a transaction for £20", you say, "Insert a transaction that entity A calls 1234, for £20". Stripe use something like this to ensure that as long as you call their API to ask for a payment and use the same key, they won't charge the person twice. https://stripe.com/docs/api#idempotent_requests https://stripe.com/docs/api#idempotent_requests
- naasking 10y agoRequesting an insert can be idempotent. Each non-idempotent operation is tagged with a unique identifier, if the server doesn't have inserted data tagged under that identifier, then it performs the insert, if it does, then it returns the usual success code as if it had just performed the insert. This unique identifier is simply a durable representation of a future which I described above.
- int_19h 10y agoThis would seem to require the identifiers to be attached to records in perpetuity (i.e. it would basically require client-generated IDs everywhere), so that the server can reliably verify that this operation has already produced a record. I can see it working, but it's a far-reaching change, that may not be easy to adopt for existing data storage schemas.
- naasking 10y ago> This would seem to require the identifiers to be attached to records in perpetuity (i.e. it would basically require client-generated IDs everywhere) Not sure what you mean by client-generated. The server-side app generates the id because it has to store and interpret it. This can be as simple as a sequence number, similar to how TCP guarantees delivery. It depends on the schema really. This is the simplest way to ensure you can perform arbitrary retries of POST in case of a network partition. This data doesn't even need to be integrated with your app's schema, although that's ideal so you can manage the storage lifetime. But you could use an entirely separate store for GUIDs and cached replies, and so it becomes transparent to your app and just becomes another layer.
- int_19h 10y ago> Not sure what you mean by client-generated. The server-side app generates the id because it has to store and interpret it. Per the description above: "Each non-idempotent operation is tagged with a unique identifier" Since the operation originates on the client, the client has to tag it with the identifier, no? And the server has to store this identifier in a way that associates it with any data affected by that operation in a non-idempotent way. Or are you saying that the client first has to make a round-trip to the server to generate the ID, and then use that server-provided ID for the actual POST?
- naasking 10y ago> Or are you saying that the client first has to make a round-trip to the server to generate the ID, and then use that server-provided ID for the actual POST? This is always the case for REST given HATEOAS, ie. you've already made some hypermedia requests to obtain the URL of the endpoint to which you will POST. Unless the resource you're posting to actually is the public entry point of your service, but that would be very unusual.