Google Cloud Pub/Sub Architecture
What you'll learn: How Google Cloud Pub/Sub provides globally distributed messaging with flexible subscription models and ordering capabilities.
Global Pub-Sub Service Design
Google Cloud Pub/Sub is a fully managed, planet-scale messaging service built on Google's infrastructure. Unlike broker-based systems (like RabbitMQ) that require you to manage servers, Pub/Sub automatically scales across regions and zones. Publishers send messages to topics, and subscribers consume from those topics through subscriptions — but the magic is in how Google handles the infrastructure underneath.
Think of it like a global postal service: you drop letters (messages) at any post office (regional endpoint), and the postal network (Google's backbone) ensures delivery to all registered recipients, no matter where they are.
Push vs Pull Subscriptions
Pub/Sub offers two delivery models:
Pull subscriptions: Your application actively requests messages from Pub/Sub. You control the pace—like checking your mailbox when you're ready. Best for batch processing or when you want backpressure control.
Push subscriptions: Pub/Sub delivers messages via HTTP POST to your webhook endpoint. Messages arrive automatically—like a courier delivering to your door. Ideal for serverless functions or auto-scaling applications.
Ordering Guarantees
By default, Pub/Sub prioritizes throughput over strict ordering—messages may arrive out of sequence. However, you can enable ordering keys: messages with the same key are delivered in order. This trades some parallelism for predictability, useful when processing events for the same user or entity must happen sequentially.
Without ordering keys, Pub/Sub treats the system like multiple lanes of traffic moving independently—faster but not sequential. With ordering keys, it's like a single-file lane—orderly but potentially slower.
Key Takeaway: Google Cloud Pub/Sub provides globally distributed messaging with pull or push delivery models, defaulting to unordered high-throughput delivery unless you explicitly enable ordering keys for specific message sequences.