TECH_COMPARISON
Google Pub/Sub vs Kafka: A Detailed Comparison for System Design
Compare Google Cloud Pub/Sub and Apache Kafka on scalability, operations, ordering, and pricing for event-driven architectures.
Google Pub/Sub vs Kafka
Google Cloud Pub/Sub and Apache Kafka both enable asynchronous messaging and event streaming, but their operational models are fundamentally different. Pub/Sub is a fully managed, serverless messaging service. Kafka is a self-managed distributed streaming platform.
Architecture Differences
Pub/Sub abstracts away all infrastructure. You create topics and subscriptions. Google handles partitioning, replication, scaling, and failover. There are no brokers to manage, no partitions to count, and no rebalancing to worry about.
Kafka gives you full control over partitions, replication factors, broker configurations, and retention policies. This control enables optimization but requires expertise.
Ordering and Delivery
Pub/Sub supports ordering via ordering keys — messages with the same key are delivered in order. Without ordering keys, messages may arrive out of order. Kafka guarantees ordering within partitions, and partition assignment is deterministic.
Pub/Sub delivers messages at least once by default. With Dataflow, you can achieve exactly-once processing. Kafka supports exactly-once semantics natively with idempotent producers and transactional writes.
Retention and Replay
Pub/Sub retains acknowledged messages for 7 days by default (up to 31 days). You can seek subscriptions to a timestamp for replay. Kafka retains messages based on time or size policies and supports indefinite retention — consumers can seek to any offset in the log.
For event sourcing patterns that require replaying years of history, Kafka's unlimited retention is essential. For shorter retention needs, Pub/Sub's managed approach is simpler.
The Verdict
Pub/Sub wins on operational simplicity and automatic scaling. Kafka wins on control, ecosystem, and long-term retention. In system design interviews, choose Pub/Sub for GCP architectures and Kafka for multi-cloud or stream-processing-heavy designs. Check our concepts guide for messaging fundamentals.
GO DEEPER
Master this topic in our 12-week cohort
Our Advanced System Design cohort covers this and 11 other deep-dive topics with live sessions, assignments, and expert feedback.
// RELATED_COMPARISONS
Kafka vs SQS: A Detailed Comparison for System Design
Compare Apache Kafka and Amazon SQS — throughput, ordering, replay, pricing, and when to choose each for your distributed system architecture.
Kafka vs Pulsar: A Detailed Comparison for System Design
Compare Apache Kafka and Apache Pulsar on architecture, multi-tenancy, geo-replication, and performance for distributed streaming systems.
Redis Streams vs Kafka: A Detailed Comparison for System Design
Compare Redis Streams and Apache Kafka on throughput, persistence, stream processing, and use cases for real-time messaging systems.
Kafka vs Redpanda: A Detailed Comparison for System Design
Compare Apache Kafka and Redpanda on performance, compatibility, operations, and cost to choose the best streaming platform.
NATS vs Kafka: A Detailed Comparison for System Design
Compare NATS and Apache Kafka on latency, persistence, simplicity, and streaming to choose the right messaging system for your needs.
AWS Kinesis vs Kafka: A Detailed Comparison for System Design
Compare Amazon Kinesis and Apache Kafka on throughput, cost, operations, and ecosystem for building real-time streaming pipelines.