# Ordering and exactly-once delivery in Pub/Sub: what each one costs

> Ordering keys pin publishers to one region, exactly-once pins subscribers and rules out push, and neither stops a publisher retry arriving twice. Put a version in every message first, then switch each on only where a consumer needs it.

- Canonical: https://www.alpacamango.com/docs/pub-sub-ordering-and-exactly-once
- Author: Zorp
- Published: 2026-11-26 · Updated: 2026-11-22
- Topics: Google Cloud, Event-driven, Architecture

**Leave both switches off until a consumer gives you a reason. Ordering keys and exactly-once delivery each pin one end of the pipeline to one region, cap throughput and limit how messages reach your code, and neither spares the consumer a second copy. Put a business key and a per-entity version in every message first. Then switch on ordering only for events that are steps rather than snapshots, and exactly-once only for a side effect you can neither repeat nor check.**

## What an ordering key costs

Messages that share an ordering key, an order ID say, reach an ordered subscription in the sequence Pub/Sub accepted them. The bill:

- **The publishers are pinned.** Order holds only between messages published in one region, so publishers outside Google Cloud or spread across regions need a locational endpoint. Subscribers can be anywhere.
- **Each key is one lane.** Publishing is capped at 1 MBps per key, and delivery waits on your handler: one outstanding batch per key for pull, one message for push. Key on the smallest thing whose history matters (an order, not a customer) or a busy key backs up; watch `oldest_unacked_message_age`.
- **A failure stops the key.** After a publish on a key fails for good, the client rejects that key's queued and new messages until you call resume. If nothing checks the result, that order's events stop.
- **A redelivery replays the tail.** If message 2 comes back, so does 3, acknowledged or not.
- **It is fixed at creation.** You cannot switch it on for an existing subscription, and a dead-letter topic may not keep the order.

```python
publisher = pubsub_v1.PublisherClient(
    publisher_options=pubsub_v1.types.PublisherOptions(enable_message_ordering=True),
    client_options={"api_endpoint": "europe-west2-pubsub.googleapis.com:443"},
)
future = publisher.publish(topic, data, ordering_key=order_id)
try:
    future.result()
except RuntimeError:
    publisher.resume_publish(topic, order_id)  # then republish the failed messages, in order
```

## What exactly-once costs

Exactly-once delivery promises no redelivery while a message is leased or after a successful acknowledgement, and tells you whether each acknowledgement landed. The bill:

- **Pull only.** Push and export subscriptions cannot have it. Push is how Pub/Sub calls a Cloud Run service and how Eventarc Standard reaches its targets, so you need a long-running pull consumer: on Cloud Run, a worker pool.
- **The subscribers are pinned.** The guarantee needs subscribers talking to one region; publishers can be anywhere. It mirrors ordering: with both on, each end is tied to one region.
- **Slower, and on its own quota.** Latency is, in Google's word, significantly higher. The default quota is 180,000 messages consumed a minute per region (3,000 a second), higher only in us-central1, us-east1 and us-west1. With ordering too, acknowledgements must arrive in order, which Google says limits a client to thousands of messages a second.
- **Stricter acknowledgements.** An expired ack ID now fails with `INVALID_ARGUMENT`: use the client's ack-with-response call and a long minimum lease extension.

Neither switch is [priced](https://cloud.google.com/pubsub/pricing); you pay in throughput, latency and where your code may run.

## What neither one promises

Both features work on Pub/Sub's side of the line; your publisher's retries and your consumer's side effects stay on yours.

[Google's own example](https://docs.cloud.google.com/pubsub/docs/retry-requests): a publisher batches messages 1 and 2 on one key, the reply is late, and the client resends the batch. An ordered subscriber can then receive 1, 2, 1, 2, 3. The resent copies carry new message IDs, and exactly-once deduplicates on message ID, so it lets them through. A failed exactly-once acknowledgement brings the message back too, and Google's advice is to record your progress so the retry skips finished work: an idempotent consumer by another name.

**Ordering saves you a reorder buffer, not a sequence check.** For events that carry a whole state (order 8812 is shipped, version 7), one conditional write absorbs duplicates and latecomers, and neither feature adds anything:

```python
cur.execute(
    """INSERT INTO orders (id, status, version) VALUES (%s, %s, %s)
       ON CONFLICT (id) DO UPDATE SET status = EXCLUDED.status, version = EXCLUDED.version
       WHERE orders.version < EXCLUDED.version""",
    (event["orderId"], event["status"], event["version"]),
)
```

## When each one earns its place

- **Ordering**, when each event is a step that means nothing out of sequence and every step must be acted on: change data capture applied to another store, ledger movements, a session's clickstream. You never hold step 5 waiting for step 4; you still drop the step 4 already applied.
- **Exactly-once**, when the side effect can be neither repeated nor checked: a text message, a partner API with no idempotency key. Pub/Sub then never hands out a second copy mid-lease, so its own redeliveries need no claim-before-you-act lock, and it reports a failed acknowledgement instead of hiding it. A crash between the side effect and your progress record still gets through, as does the publisher's retry.

Everything else wants the plain subscription, push included, and the consumer from [idempotent consumers and dead-letter topics](/docs/pub-sub-idempotent-consumers-dead-letter).

## On AWS and Azure

SQS FIFO queues order by message group ID and drop a resend carrying the same deduplication ID within five minutes. Azure Service Bus, on Standard and Premium, orders by session and drops a resend whose `MessageId` it saw within its window (10 minutes by default, up to 7 days). Both deduplicate on something the producer controls, so both catch the producer retry that Pub/Sub's exactly-once lets through. None of the three makes a side effect happen once.

## The diagram

One topic, three subscriptions, each with only the switch its consumer needs: default push into a Cloud Run service that keeps the newer version, ordered pull into a ledger worker pool, and exactly-once pull into the worker pool that sends text messages. [Open it in archhy](https://archhy.com/d/WJrFdf4XL7s5?utm_source=alpacamango) and make a copy.

Reference documentation: [Pub/Sub message ordering](https://docs.cloud.google.com/pubsub/docs/ordering), [exactly-once delivery](https://docs.cloud.google.com/pubsub/docs/exactly-once-delivery), [Pub/Sub quotas](https://docs.cloud.google.com/pubsub/quotas), [SQS FIFO key terms](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-key-terms.html), [Service Bus sessions](https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions), [Service Bus duplicate detection](https://learn.microsoft.com/en-us/azure/service-bus-messaging/duplicate-detection).
