Skip to content

Cross-zone delivery

Google bills traffic between two zones of a region at $0.01 per GiB in each direction. A lowtide cluster runs in two zones, so it is built to keep delivery inside a zone.

Each zone has its own shards of every subscription, 8 per zone by default. A zone’s shards cover the messages published in that zone, and pods in that zone serve them. A consumer in a zone therefore receives the messages published in its zone, read from memory on a pod next to it. Acknowledgements go back to the pod that delivered the message.

This holds for pull, streaming pull, push, BigQuery and Cloud Storage subscriptions, and for messages with an ordering key.

Two cases move a zone’s shards to pods in the other zone:

Case When Ends when
Fallback The zone has no consumers of the subscription (no pod there has a consumer attached). A consumer connects in that zone.
Spill A message of the zone’s shards has waited 5 seconds for a consumer, and the other zone keeps up. The other zone then takes the share of the zone’s shards that the zone’s consumers can’t keep up with, at least one. For a minute, the zone’s consumers wait for nothing (under 1 second) and the zone publishes no more than they handled while behind.

The wait counts from when a message became ready for a consumer. Redeliveries after a nack or an expired deadline, and messages replayed by a seek, don’t count the time before that.

Spill needs consumers in the other zone that keep up. If both zones fall behind, nothing moves.

Each gateway pod spreads the messages it receives over 8 writer streams, and each stream belongs to one shard, so even one gateway pod’s messages are spread over all of its zone’s shards. Messages with an ordering key are the exception: all messages of a key go to the same stream, so they stay in order.

Spill moves only shards that have messages waiting. lowtide measures how many messages per second the zone’s consumers handled while they were behind, and how many the zone publishes to each shard. It keeps as many busy shards in the zone as those consumers can handle and moves the rest, at least one. For example, if a zone publishes 200 messages per second and its consumers handle 32, one of its 8 shards (25 messages per second) stays and 7 move: the other zone delivers most of the zone’s messages, and the zone’s own consumers keep receiving the rest. If the consumers still fall behind on what stayed, more shards move, at most once every 10 seconds. Shards with nothing waiting stay in their zone.

While spill is on, the zone’s own consumers have less to do and catch up. Spill still stays on while the zone publishes more than they handled before, so shards don’t move back and forth. If they stay too slow, lowtide hands the shards back once every 10 minutes to check whether they have become faster.

In both cases the pods in the other zone read the zone’s messages one of two ways. You choose which, per subscription.

Path Reads from Latency Cost
Fastest (default) The other zone’s pods, from memory Same as in-zone delivery $0.01 per GiB read
Lowest cost Cloud Storage segments About 1 second more (one upload window) No inter-zone charge

The setting changes nothing while each zone has its own consumers.

Set it for one subscription with the label lowtide-cross-zone:

Terminal window
gcloud pubsub subscriptions update orders-analytics \
--update-labels=lowtide-cross-zone=lowest-cost

Remove the label to use the cluster default again. Any other value is refused.

The cluster default is fastest unless the gateway’s configuration says otherwise (config.crossZone in the Helm chart). You can also set it in the console, which takes precedence over the configuration.

The console’s cluster page has a Cross-zone tab. It shows, for each subscription, the bytes read across zones this month and what they cost at $0.01 per GiB. Its switch sets the same label, or the cluster default. The change goes to the cluster’s agent, which applies it within about a minute. The agent applies it even when it sends hashed names to lowtide Cloud.

If Terraform manages your subscriptions’ labels, set lowtide-cross-zone in Terraform instead. A label set from the console would be removed by the next terraform apply.

The bytes are measured, not estimated. Each pod counts what it reads from the other zone in lowtide_cross_zone_bytes_total (Metrics), and the agent reports it hourly. The console subtracts the cost from the saving it shows on the Overview and Savings pages.

When a subscription’s cross-zone cost for the month is more than 10% of its cluster’s saving, the console shows a notice. It names the zone that has publishers but no consumers. lowtide never switches a subscription to Lowest cost on its own.

A rough figure: a subscription whose consumers all run in one zone, with publishers in both zones, reads about half its messages across zones on Fastest. At 1 TiB delivered a month, that is about 512 GiB, or $5.12.

  • Run consumers of each subscription in both zones. With two replicas, use a topology spread constraint on topology.kubernetes.io/zone.
  • If a subscription’s consumers must run in one zone and can wait a second, set it to Lowest cost.
  • Keep consumers fast enough that a message never waits 5 seconds, or accept that spill moves part of the work to the other zone.
  • Connect clients through the zone-local endpoints below, so the client’s own connection stays in its zone.

Clients in the cluster use the Service lowtide.<namespace>.svc, which routes to a pod in the client’s zone.

Clients elsewhere in the VPC, such as VMs or Cloud Run with Direct VPC egress, use the internal load balancer. The Terraform module turns on zonal affinity for it (endpoint_zonal_affinity). A client VM is then sent to gateway pods in its own zone while that zone has ready pods, and to the other zone otherwise. This needs GKE 1.33.3-gke.1392000 or later and GKE subsetting, which the module turns on for a cluster it creates. Clients in other regions, through global access, are not zonal. Cloud Run with Direct VPC egress does not tell its instances’ zones; see Consumers on Cloud Run.

With the Helm chart alone, set spec.trafficDistribution: PreferClose on your own LoadBalancer Service to get the same.

Without zonal affinity, the load balancer spreads clients over both zones. About half the client connections then cross zones, in both directions, and that traffic is not counted by lowtide. A consumer proxied to a pod in the other zone is counted (path="proxy").

Pods of this version write several writer streams. Pods of earlier versions serve and read them like any other pod’s messages, so you can upgrade one pod at a time. While pods of the previous release still serve a subscription, spill places shards the way that release does (it shares the busy shards between both zones), so that all pods agree on who serves what. A pod that stops gracefully uploads all of its messages first, so rolling back to the previous release after a normal shutdown loses nothing.

Versions before zone-aware delivery split each subscription into shards across all zones. After an upgrade, a subscription switches to zone shards once every pod serving it runs the new version, about 30 seconds after the last pod starts. All pods switch together. It switches back at once if a pod of the earlier version joins. Acknowledgement positions are kept per writer, so the switch moves no data. Messages delivered but not yet acknowledged at the moment of the switch can be delivered again.

Rolling back to a version before zone-aware delivery works, with one risk we accept. Earlier versions don’t know about zone shards, so they can’t wait for them. For about a second after each older pod starts, it can serve messages that a newer pod is also serving. Those messages can be delivered twice, and messages with an ordering key can arrive out of order. Nothing is lost. Roll back when traffic is low, and expect some duplicates.

During a zone failover, a pod moves to the other zone with its disk, and the messages it writes then belong to that zone. For 45 seconds after the move, no zone serves them. That gives every pod time to see the move, so two pods never serve the same messages. The pod’s messages are delayed by up to 45 seconds, not lost.