Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Implement Idempotency-Key for POSTing statuses #2723

Open
VyrCossont opened this issue Mar 5, 2024 · 2 comments · May be fixed by #3186
Open

[feature] Implement Idempotency-Key for POSTing statuses #2723

VyrCossont opened this issue Mar 5, 2024 · 2 comments · May be fixed by #3186
Labels
enhancement New feature or request frontend-api Backend requirement for Frontend stuff
Milestone

Comments

@VyrCossont
Copy link
Contributor

VyrCossont commented Mar 5, 2024

Is your feature request related to a problem ?

As a user on a phone with a bad connection, I want to avoid both losing my post if my network connection drops, and double-posting if it's not clear if my post went through.

As a mobile client dev, I want to be able to retry creating a status if I get an error indicating that it might have failed.

Describe the solution you'd like.

Implement the Idempotency-Key header for the POST /api/v1/statuses endpoint. This header can be optionally set by clients to a UUID, ULID, or other short random string, and is used to de-duplicate operations requested with the same idempotency key in a given time window, an hour in Mastodon's case.

For complete Mastodon API compatibility, if we ever implement scheduled statuses, this would also involve adding an idempotency field to the ScheduledStatus type returned from scheduled status APIs.

Describe alternatives you've considered.

Storing the status text, CW, poll, media attachment IDs, etc. client-side, retrieving the user's recent statuses after a potentially failed POST (and possibly a short delay), and checking for duplicates. This requires extra network traffic and extra work for the client, but doesn't require any server-side changes.

Additional context.

Mastodon only implements it for creating statuses, but the same mechanism could be used to make any API call idempotent.

It could be implemented as an in-memory per-user set of idempotency keys, as an extra column on the statuses table, or as a separate table. Some databases have performance issues with tables that are frequently appended to and deleted from; partitioning such a table and dropping old partitions perodically can mitigate that problem, removing the need to vacuum in PG.

@VyrCossont VyrCossont added the enhancement New feature or request label Mar 5, 2024
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc added this to the v0.16.0 milestone Apr 2, 2024
@tsmethurst tsmethurst modified the milestones: v0.16.0, v0.17.0 Jun 6, 2024
@VyrCossont VyrCossont added the frontend-api Backend requirement for Frontend stuff label Jul 23, 2024
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc linked a pull request Aug 9, 2024 that will close this issue
10 tasks
@tsmethurst tsmethurst modified the milestones: v0.17.0, v0.18.0 Aug 9, 2024
@rochacbruno
Copy link

rochacbruno commented Oct 2, 2024

I was about to open similar issue, just for the record, I found this problem when trying to schedule a post using Tusky client.

Reference:
https://go.rocha.social/@bruno/statuses/01J95XX6VZ3FW5K6GRR7V4H94K

@VyrCossont
Copy link
Contributor Author

VyrCossont commented Oct 2, 2024

@rochacbruno We don't actually have scheduled posts, so you would have hit another issue very quickly. That's tracked in #1006.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request frontend-api Backend requirement for Frontend stuff
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants