GuideUpdated
How to stop duplicate posts when retrying a social media API
Duplicates come from retrying a create call whose answer you never saw, or from a worker that dies mid-send. Siar, a unified social media API, has no client idempotency key on post creation: resend a create call and you make a second post. Check by your own reference first. After that, Siar claims each network target once.
Where duplicate posts come from
- Your retry. The create request times out or the connection drops. You cannot tell whether the API stored the post, so you send it again.
- The API's retry. A worker sends the post to the network, then crashes before it saves the result. When the job runs again, it does not know the post is already live.
- Two senders. A double click, two cron jobs, or a queue that delivers the same job twice.
The first is yours to guard. The second and third are the API's.
Three ways an API can guard against them
| Approach | How it works | What it covers |
|---|---|---|
| Client idempotency key | You send a unique key with the create call, usually an Idempotency-Key header (IETF draft). A repeat with the same key gets the first answer back. | Your retry |
| Unique reference key | You store your own id on the post. The API refuses a second post with the same id and lets you look it up. | Your retry, if you look before you resend |
| Server-side claim | The API marks each send as taken before it calls the network, and checks the account when a send was cut off. | The API's retry and two senders |
Some APIs offer a client key. PostWire, for example, says "An identical post is refused for two minutes, or 24 hours with your own idempotency_key" (PostWire home page, checked ).
What Siar does not do
- Siar has no client idempotency key on post creation, and no
Idempotency-Keyheader. - Resending a create call without a reference key creates a second post.
- Siar does not refuse a post because its text matches an earlier one.
Check by your own reference first
POST /api/v1/post/ takes an optional referenceKey of up to 128 characters, unique in your organization. Use your own id: a release tag, an order number, a row id.
- Before you create, call
GET /api/v1/post/reference-key/{referenceKey}. A404means no post has that key yet. - Create the post with the key.
- If the create call times out, do not resend it blind. Look the key up again.
- If a create comes back
409 Conflict, the post already exists. Read it by its key.
# Example: check by your own reference before creating a post.
REF="release-v1.4.0"
code=$(curl -s -o /dev/null -w '%{http_code}' \
-H "x-api-key: $SIAR_API_KEY" \
"https://api.siaran.my/api/v1/post/reference-key/$REF")
if [ "$code" = "404" ]; then
curl -s -X POST "https://api.siaran.my/api/v1/post/" \
-H "x-api-key: $SIAR_API_KEY" \
-H "content-type: application/json" \
-d '{
"teamId": "TEAM_ID",
"title": "Release v1.4.0",
"referenceKey": "'"$REF"'",
"postDate": "2026-11-12T09:00:00.000Z",
"status": "SCHEDULED",
"socialAccountTypes": ["MASTODON", "BLUESKY"],
"data": {
"MASTODON": { "text": "v1.4.0 is out." },
"BLUESKY": { "text": "v1.4.0 is out." }
}
}'
fi HTTP/1.1 409 Conflict
content-type: application/json
{
"statusCode": 409,
"message": "A post with referenceKey \"release-v1.4.0\" already exists."
} A reference key is not an idempotency key. The repeat gets a 409, not a copy of the first answer, so your code must handle both.
What Siar does once a post is accepted
A post becomes one target per network: one account in one post. Each target is handled on its own. The sent-once design is described with the rest of the publishing pipeline.
- One claim per target. Before calling a network, Siar moves the target from pending to processing in one conditional database update, with a fresh attempt id. Only the worker whose update succeeds sends. A restart, a duplicate job or a second worker finds nothing to claim.
- The network's id is kept at once. The moment the network returns its post id, Siar saves it against that attempt.
- Short failures retry on their own. When a network says to try later, the target goes back to pending and is sent again, up to 3 attempts in all, after the network's reset time or a growing delay. These do not use your manual retries.
When a send is interrupted
If a target has been processing for more than 20 minutes with nothing left to poll, the worker stopped between the network call and the save. Siar does not resend straight away.
- It reads the account's recent posts, from a minute before the claim.
- It looks for a post that starts with the same text, using the first 60 characters.
- If it finds one, it marks the target posted and keeps that post's id.
- If it finds none and the network can be checked, it sends again, within the same 3 attempts.
- If the network gives no way to look, Siar stops. Today that is Discord and Slack. The target ends as failed, with a verdict of
unknown:
{
"MASTODON": {
"code": "UNKNOWN",
"errorMessage": "Publishing was interrupted and the result could not be confirmed. Check the account before retrying.",
"retryability": "unknown"
}
} Two limits to know. The match is on text, so a post with no text cannot be found this way and is sent again. And a network can take a moment to list a new post, so a very recent post may be missed.
Retrying a failed post
POST /api/v1/post/{id}/retry sends again only the networks that ended in error. Networks that posted are left alone. A post can be retried up to 6 times, and a retry does not count as another post on your plan. Check the account first when the verdict was unknown.
Webhook handlers need the same care
Siar retries a webhook delivery when your endpoint does not answer with a success, so your handler can see the same event twice. Deduplicate on the x-siar-delivery header or the event id, which stays the same across redeliveries. The webhook docs show signature checks in Node.js and Python.
Frequently asked questions
Does Siar support idempotency keys?
Not on post creation. There is no Idempotency-Key header, and resending a create call without a reference key creates a second post. Each network target in a post is claimed once, and an interrupted send is checked against the account before anything is re-sent.
What does referenceKey do?
It is an optional key of up to 128 characters, unique in your organization. A second create with the same key is refused with 409 Conflict, and GET /api/v1/post/reference-key/{referenceKey} returns the post that has it. It does not replay the first response.
Can retrying a failed post publish it twice?
No. POST /api/v1/post/{id}/retry sends again only the networks that ended in error, up to 6 times. Networks that already posted are left alone.
What happens if Siar stops in the middle of a send?
After 20 minutes, Siar reads the account’s recent posts and looks for one that starts with the same text. If it finds it, the target is marked posted. If the network gives no way to look, the target ends as “could not be confirmed” instead of being sent again.