Idempotency that works with Litestar #4964
violetta98
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello everyone!
I got tired of rewriting idempotency in every service and getting it slightly wrong, so I packaged it. Posting here because the core is plain ASGI, not FastAPI-specific like most Python options.
Call it twice with the same
order_idand the charge happens once. A concurrent duplicate waits for the first call and gets its result rather than an error.Under the hood it's an atomic claim rather than check-then-act, a lease that expires on the storage server's clock, and a fencing token so a stalled worker can't overwrite a newer result.
There's also HTTP middleware that replays the first response for retries with the same
Idempotency-Key. It's raw ASGI so it should slot intomiddleware=[...], but I've only tested it on Starlette and FastAPI. If you try it on Litestar and it misbehaves, tell me and I'll add a proper adapter.https://github.com/idemkit/idemkit, Apache-2.0
If you find it useful, I'd appreciate a star. It's new, so visibility helps a lot right now.
All reactions