Skip to main content

Question 8 of 50

Kafka versus Google Pub/Sub

SeniorTech Lead

Question

"Do you know Google Pub/Sub? How does it compare to Kafka?"

What the interviewer wants to assess

Less common than RabbitMQ/SQS, but it comes up at companies on a GCP stack. It checks whether you understand that "managed" isn't synonymous with "identical to Kafka," and whether you know where the semantics diverge.

Resposta rápida

Google Pub/Sub is a fully managed pub/sub service, with configurable retention (up to 31 days) and replay support via seek. The key difference is that it has no equivalent to Kafka's partition/offset concept — ordering is optional, via an ordering key, and comes at a throughput cost when enabled. Operationally, it's the closest thing to "Kafka without running a cluster," but with different semantics.

Resposta nível Sênior

Pub/Sub solves much of what Kafka solves — multiple independent subscribers to the same topic, configurable retention, the ability to reread messages — but with a different data model. There's no partition as a unit of parallelism and ordering; instead, there's an optional ordering key that guarantees order for messages with the same key, at the cost of lower throughput on that flow. Operations are zero for the team — there's no cluster to manage, unlike self-hosted Kafka. In practice, for teams already committed to Java/Spring and Kafka's client ecosystem (Spring Kafka, Kafka Streams), migrating to Pub/Sub has a rewrite cost; for GCP-native teams with no prior Kafka investment, Pub/Sub removes the operational complexity of a cluster, at the cost of less control over parallelism/ordering.

In-depth explanation

See the full comparison in Chapter 2.

Exemplo financeiro

A bank reconciliation system that needs to guarantee strict event ordering per account would pay the cost of an ordering key per accountId in Pub/Sub — conceptually equivalent to partitioning by key in Kafka, but with a different, explicit throughput penalty in Pub/Sub.

"Pub/Sub and Kafka are interchangeable, just swap the client"

The absence of the partition/offset concept changes the semantics of ordering and consumption parallelism. Migrating between them isn't a trivial library swap — it requires redesigning the partitioning/ordering strategy.

Pode vir a seguir

May come next: "how does ordering work without a partition?" and "would you use Pub/Sub for a system already mature on Kafka?".