[MUSIC PLAYING]
CHLOE CONDON: If you're looking for tips and tricks
on publishing with Pub/Sub, then you're in the right place.
Hi.
I'm Chloe, and in this video, I'll
be sharing six best practices when publishing with Pub/Sub.
Let's get started.
[MUSIC PLAYING]
Number one, batch messages.
By batching messages, you can increase throughput,
but larger batches also mean increased latency.
Depending on your number of publishers in combination
with flow control and batch settings,
you'll be able to make decisions around the right optimizations
for your specific usage.
Your goal should be to consider the message size and publisher
throughput to optimize for cost and latency.
Check out links in the description
below for a blog post with more information.
Number two, be mindful when using ordering keys.
Publishing messages with an ordering key
might slightly increase end-to-end message delivery
latency, since Cloud Pub/Sub takes steps to coordinate
the storage and delivery of messages
across different servers when using order delivery.
Generally speaking, when you want to optimize for latency,
you should enable batching, since the client will
wait for the batch to fill up before sending
the batch to Cloud Pub/Sub.
However, with ordering keys, if a batch of messages
fails to publish, they will be retried
and can mess up the publish order.
We recommend when you publish with ordering keys,
you disable batching.
That is, set batch settings to allow only a single message
to ensure messages are published in order one by one.
Publish the next message only when the previous one
has been successfully received by the Pub/Sub server.
Number three, use a regional endpoint.
Another must-do when publishing with ordering keys
is to use a regional endpoint.
Since order delivery is only guaranteed within a region,
using a regional endpoint instead of a global endpoint
to publish messages to the same region
can be especially useful.
This can be done by configuring your message storage policy.
You can either synchronize it with the organization policy
or specify it explicitly for a topic.
Number four, consider bandwidth.
Your publish throughput is constrained
by your network bandwidth as well as the number of requests
you are sending.
If your bandwidth is good but your network latency is high,
you don't want to overwhelm the system
with too many small requests.
You can also use publisher side flow control
to help with client-side network issues.
Number five, provision your publishers.
Your publish throughput is also CPU and memory-bound.
More available machine cores allow
you to set higher thread count for better publish throughput.
To learn more about how to maximize streaming performance,
check out our links in the description
for a blog post that dives deeper into this topic.
And number six, customize your own default retry settings.
When publish requests time out, you
will get deadline exceeded errors.
These are automatically retried by the client libraries,
but you can tweak the default retry settings
with different initial timeout, retry multiplier, and total
timeout values.
Check out the Pub/Sub documentation
to learn more about recommended initial deadline
and total timeout.
There you have it-- six best practices for publishing
with Pub/Sub.
Thanks for joining, and keep an eye out
for more best practice videos.
And take a look at our Pub/Sub documentation
for even more tips and tricks for publishing with Pub/Sub.