Pub/Sub Best Practices
Pub/Sub Best Practices: Client Library
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 5 of 6
In this collection Browse 6 summaries 5 of 6
Pub/Sub client libraries handle publishing, receiving messages, and acknowledgement deadlines on behalf of application code. Chloe explains how client reuse and flow control can reduce delays and keep the application from taking on too much work.
Key points
- The language recommendation depends on the benchmark: Chloe recommends Java over Python for performance in 2023 and points to a linked comparison, but gives no workload or measurements in the episode. This is not a general result for every application 00:00–01:03(opens in a new tab).
- Reuse publisher clients: The first publish request takes longer than subsequent ones. Keeping the client avoids paying that startup cost again for each message 00:00–02:06(opens in a new tab).
- Flow control limits work in progress: Chloe suggests publisher flow control when requests frequently time out with high latency, and lower subscriber limits to process fewer messages at once 01:03–02:06(opens in a new tab).
- Client upgrades can carry fixes and features: New releases may fix critical issues or be required for newer Pub/Sub features 01:03–02:06(opens in a new tab).
- The Node.js examples favor asynchronous operations: In its 2023 library examples, the episode uses
subscription.onto receive messages andtopic.publishMessageortopic.flowControlledto publish them. Where methods allow callbacks or promises, Chloe recommends promises/async for performance 01:03–03:02(opens in a new tab). - Let the library manage acknowledgement deadlines: Chloe recommends streaming pull because the libraries manage
modAck, the operation that changes or extends a message's acknowledgement deadline 02:06(opens in a new tab).
Full video: https://www.youtube.com/watch?v=F0H9qt1w9JE(opens in a new tab)