with-agents

Pub/Sub Best Practices

Pub/Sub Best Practices: Publishing

Publishing, subscribing, feature, latency, client-library, and testing trade-offs

Six 2023 episodes explain Pub/Sub trade-offs in batching, retries, ordering, flow control, retention, regional placement, and testing. Recommendations reflect the client libraries and service behavior discussed in that series.

Google Cloud Tech 1 of 6
In this collection Browse 6 summaries 1 of 6

Publishing settings determine how long messages wait before being sent and how much work a Pub/Sub client can handle. Chloe explains the tradeoff between batching for throughput and sending ordered messages one at a time.

Key points

  • Batching sends more messages together, but makes them wait: Larger batches can increase throughput while adding delay before publication. Chloe recommends choosing settings from message size, publisher throughput, cost, and acceptable latency 00:00–01:03(opens in a new tab).
  • Ordering changes the batching recommendation: An ordering key identifies messages whose order must be preserved. Retrying a failed batch can disrupt publication order, so the episode recommends one-message batches and waiting for the server to receive one message before publishing the next 00:00–02:06(opens in a new tab).
  • Use a regional endpoint with ordering keys: The episode says ordered delivery is guaranteed only within a region, so it recommends a regional endpoint that publishes messages with ordering keys to the same region 01:03–02:06(opens in a new tab).
  • Publishers have client-side resource limits: Publish throughput depends on network bandwidth, the number of requests, and the publisher's CPU and memory. When network latency is high, Chloe advises against sending many small requests. More CPU cores allow more threads, and publisher-side flow control can help with client-side network issues 02:06–03:10(opens in a new tab).
  • Timed-out requests are retried by the client library: A publish timeout produces a deadline-exceeded error. Chloe points to the initial timeout, retry multiplier, and total timeout as settings that can be adjusted rather than always accepting the defaults 02:06–03:53(opens in a new tab).

Full video: https://www.youtube.com/watch?v=Oo5PXA4idI8(opens in a new tab)

Search

Search field guides and resources across the site.

    Keyboard shortcuts

    Press ? to open this guide (usually Shift + /). Close it before using other site shortcuts.

    Show keyboard shortcuts
    ?
    Search site
    Ctrl + K
    Close the current dialog or menu
    Esc

    Site shortcuts are ignored while typing. Browser and extension shortcuts may take priority.