News for hackers. Stuff that matters.
Re:Request bodies in GET requests by tptacek on Monday January 31, 2022 @06:26PM (#30156306)
There's a bunch of different ways to do this, and upthread I just gave a sketch. I can tell you what we do at Fly.io --- or rather, what we suggest our users do:

* We have an HTTP header you can set in a reply that says "replay this request elsewhere".

* We boot up clusters of Postgres servers in read-replica configurations --- a single writer, lots of readers.

* If you try to write to a read replica, you get an error from Postgres, and your framework passes that error up to you.

* We suggest our users catch the exception and set the "replay elsewhere" header to redirect the request to the write master.

And that's pretty much it. Most apps are read-heavy. Reads get serviced from replicas (and, usually, close to their users --- that's the point of the service we built) and writes go to the single write master. You don't write any serious code to make that work.

But if apps could reliably say "a POST isn't just a complicated GET, but is almost certainly changing mutable serverside state", this would be an even easier problem; you'd just have the CDN route POSTs to the write master region, and GETs to the nearest region, and you'd be done.

You can architect your apps like this today, I guess, using QUERY or abusing PUT or something. My point is just that there's significant value in being able to shift all the read-only operations out of POST.

There are no comments on this comment yet.