FIELD NOTESGOOGLE CLOUD · ARCHITECTURE

Event-driven architecture on Google Cloud: the patterns and when to use each

Cloud Tasks, Pub/Sub, Eventarc or Workflows: choose by who must know an event happened, who sets the delivery rate, and what breaks if it arrives twice, late or never. Why the retry defaults, not the product, decide whether an event is lost.

By Glorb4 min readPublished
ON THIS PAGE
An order service sends work three ways: a Cloud Tasks queue to a rate-limited payments API, a Pub/Sub topic with a copy for each subscriber, and Workflows calling step services in turn; an Eventarc trigger carries invoice bucket events to a parser. Drawn in archhy.

On Google Cloud, choose between Pub/Sub, Eventarc, Cloud Tasks and Workflows by asking who must know an event happened, who sets the pace, and what breaks if it arrives twice, late or never. One named service working at a rate you choose wants Cloud Tasks; every interested service taking its own copy wants Pub/Sub; events from Google services, matched by filter, want Eventarc; an order of steps that is the business rule wants Workflows. Then check the retry settings: they decide "never" more than the product does.

Who must know, and who sets the pace#

  • Pub/Sub suits a publisher that should not know who listens. Each subscription keeps its own copy and backlog. A pull subscriber sets its pace with flow control; with push, Pub/Sub sets it, speeding up while your service succeeds and backing off when it fails.
  • Cloud Tasks reverses that: the producer names the endpoint, and the queue sets the pace with a dispatch rate and a concurrency cap, suiting a rate-limited API you do not own. Tasks can be scheduled, and a second task with the same name is refused.
  • Eventarc routes events from Google services and your own publishers to Cloud Run, GKE or Workflows. Standard is one trigger per route, carried on Pub/Sub; Advanced adds a central bus, CEL filters and pipelines that can reshape an event.
  • Workflows owns a sequence of calls; each execution knows which step it reached and why it stopped.

With push, a consumer can ask for less only by failing. If that is the wrong signal, put Cloud Tasks or a pull subscriber in front.

Twice is the default, so design for it#

Pub/Sub, Eventarc and Cloud Tasks deliver at least once. Pub/Sub's exactly-once delivery covers only pull subscribers in one region, so push and Eventarc consumers can see a message twice. Naming a Cloud Tasks task stops it being created twice, not delivered twice. Eventarc's duplicate key, source plus id, catches only redeliveries; where the producer can repeat itself, key on the business operation, claim it as in progress before the side effect and mark it done after, as in idempotent consumers on SQS and Lambda.

Late and never are defaults you may not have chosen#

  • A Pub/Sub subscription keeps an unacknowledged message for seven days by default (up to 31), and retries immediately unless you set a backoff. Idle for 31 days, it is deleted unless set never to expire: mind a consumer that runs quarterly.
  • An Eventarc Standard trigger delivers through a Pub/Sub subscription with 24 hours of retention, after which a failing event is discarded unless that subscription has a dead-letter topic. Created on the console's Cloud Run page, a trigger makes a single attempt.
  • An Eventarc Advanced pipeline makes five attempts by default, 1, 2, 4 and 8 seconds apart, so a consumer down for about 15 seconds misses the event. It has no dead-letter destination.
  • A Cloud Tasks task that uses up its attempts and retry window is deleted; log the last failure yourself.

For both Eventarc editions, give every consumer that must not miss an event its own Pub/Sub subscription, with longer retention and a dead-letter topic. Behind an Advanced pipeline, route to a Pub/Sub topic and set a backoff on the subscription you add, which otherwise retries immediately. A Standard trigger's subscription already backs off; extend it:

Shell
SUB=$(gcloud eventarc triggers describe invoices-to-parser --location=europe-west2 \
  --format='value(transport.pubsub.subscription)')
gcloud pubsub subscriptions update "$SUB" \
  --message-retention-duration=7d \
  --dead-letter-topic=invoices-dead-letter --max-delivery-attempts=10

Grant the Pub/Sub service agent publisher rights on the dead-letter topic and subscriber rights on the subscription, or nothing is forwarded. Unacknowledged messages kept past 24 hours add storage charges.

When the order of steps is the rule#

When billing must wait for stock and a failed shipment must refund the charge, chained handlers spread that state across services, and finding one order means searching every log. A Workflows execution keeps it in one history and can wait up to a year for a callback. Waiting runs count against a quota of 10,000 concurrent executions per region and project; beyond it, a Pub/Sub-started run fails with HTTP 429 instead of queueing. Eventarc does not retry an event whose workflow did not start, or whose run started and then failed: retry inside the workflow. Workflows ignores an event redelivered within 24 hours, but have the first step check that the order is not already running: a producer can send it twice under new event IDs. Between teams, publish events; inside one, run a workflow.

On AWS and Azure#

On AWS, SNS with an SQS queue per consumer does Pub/Sub's job, EventBridge does Eventarc's and Step Functions Workflows'. For Cloud Tasks, SQS with a Lambda at capped concurrency is the queue, and an EventBridge API destination the nearest match for its rate-limited HTTP push. On Azure, Service Bus topics replace Pub/Sub, Event Grid routes and Durable Functions orchestrate, while Service Bus scheduled messages and duplicate detection cover Cloud Tasks' scheduling and deduplication. Event-driven architecture on AWS asks these questions there; messaging across the three clouds compares ordering, replay and dead letters.

The diagram#

The four side by side: Cloud Tasks pacing a payments API, a Pub/Sub topic copying to subscribers, a workflow calling steps in turn, and an Eventarc trigger on an invoice bucket. Open it in archhy and press Make a copy to adapt it.