← TikTok Interview Insights

TikTok·Software Engineer·Onsite - System Design / Architecture·Senior

Senior
Jun 2026

Summary

TikTok system design round focused almost entirely on Kafka, and I mean deep Kafka, not the surface-level stuff. It was a long session and they kept pulling the thread on every answer I gave.

Questions Asked (6)

Q1

Walk me through Kafka's core architecture: topics, partitions, leader/follower replicas, replication factor, and in-sync replicas.

System DesignTechnical Trade-offs
Author's notes

I started with topics and partitions fine, but when they pushed on ISR behavior during a leader failure I got a bit fuzzy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start with a high-level overview of Kafka's architecture, then drill down into each component in a logical order: topics, partitions, replicas, and ISR. Use a concrete example to illustrate how data flows and how fault tolerance is achieved.

Pro tip: Emphasize the trade-offs between durability, availability, and latency when discussing replication and ISR, and relate them to real-world scenarios like TikTok's high-throughput, low-latency requirements.

1. Overview of Kafka

Briefly explain Kafka as a distributed streaming platform and its core components: brokers, producers, consumers, and ZooKeeper/KRaft. Mention that topics are the logical channels for messages.

2. Topics and Partitions

Describe topics as categories or feeds, and partitions as the unit of parallelism and scalability. Explain how partitions enable horizontal scaling and ordering guarantees within a partition.

3. Replication and Leader/Follower

Explain that each partition has a leader and multiple followers (replicas). The leader handles all reads and writes, while followers replicate the data. Discuss replication factor and its impact on fault tolerance.

4. In-Sync Replicas (ISR)

Define ISR as the set of replicas that are fully caught up with the leader. Explain how ISR is maintained and its role in ensuring durability and consistency, including the acks parameter.

5. Trade-offs and Real-World Implications

Discuss trade-offs: higher replication factor increases durability but also latency and resource usage. Explain how ISR affects producer acknowledgments and consumer reads. Relate to TikTok's scale and performance needs.

Key Points to Mention

  • Partitions as the unit of parallelism and ordering
  • Leader handles all reads/writes; followers replicate
  • Replication factor determines number of copies
  • ISR ensures only caught-up replicas are considered for leader election
  • acks=all ensures message is written to all ISR before acknowledgment
  • Trade-offs: durability vs. latency vs. resource cost

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How do producers decide which partition to send a message to, and how do you configure acknowledgment behavior?

System DesignTechnical Trade-offs
Author's notes

This one I felt okay about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the default partitioning strategy in Kafka (or similar systems) and when to override it with a custom partitioner. Then, discuss the trade-offs between different acknowledgment settings (acks=0, 1, all) in terms of durability, latency, and throughput, and how to configure them based on the use case.

Pro tip: Mention that while acks=all provides the strongest durability, it can be combined with min.insync.replicas to balance durability and availability, and that idempotent producers can prevent duplicates even with retries.

1. Default Partitioning

Explain that if no partition is specified and no key is provided, the producer uses a round-robin or sticky partitioning strategy to distribute messages evenly across partitions.

2. Key-Based Partitioning

Describe that when a key is provided, the producer hashes the key (using a consistent hashing algorithm) to determine the partition, ensuring all messages with the same key go to the same partition.

3. Custom Partitioning

Discuss that for advanced use cases, you can implement a custom partitioner to control message routing based on business logic, such as prioritizing certain keys or ensuring even load.

4. Acknowledgment Configuration

Detail the acks parameter: acks=0 (no acknowledgment, lowest latency, possible data loss), acks=1 (leader acknowledgment, balanced), acks=all (all in-sync replicas acknowledge, highest durability).

5. Trade-offs and Best Practices

Explain how to choose acks based on requirements: use acks=all for critical data, acks=1 for moderate durability, acks=0 for high throughput. Mention min.insync.replicas and idempotent producer for exactly-once semantics.

Key Points to Mention

  • Default partitioner behavior: round-robin or sticky partitioning when no key is provided.
  • Key-based partitioning: hash of key determines partition, ensuring order for same key.
  • Custom partitioner: implement Partitioner interface to control partitioning logic.
  • acks=0: fire-and-forget, lowest latency, highest throughput, but possible data loss.
  • acks=1: leader writes to local log and responds without waiting for replicas; balanced durability and latency.
  • acks=all: leader waits for all in-sync replicas to acknowledge; highest durability, higher latency.
  • min.insync.replicas: minimum number of replicas that must acknowledge for a write to be successful when acks=all.
  • Idempotent producer: prevents duplicate messages due to retries, useful with acks=all for exactly-once semantics.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Explain how consumer groups manage offset commits and what happens during a rebalance.

System DesignTechnical Trade-offs
Author's notes

Probably my weakest answer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining consumer groups and their role in Kafka, then explain the offset commit mechanism (auto vs manual) and how offsets are stored. Next, describe the rebalance process, including triggers, phases, and what happens to offsets during rebalance. Finally, discuss trade-offs and best practices to ensure exactly-once or at-least-once semantics.

Pro tip: Emphasize that during a rebalance, consumers cannot commit offsets, so understanding the impact on processing guarantees is crucial. Mention how TikTok's scale might require tuning session timeouts and using cooperative rebalancing to minimize disruption.

1. Define Consumer Groups and Offset Management

Explain that a consumer group is a set of consumers that cooperatively consume a topic's partitions. Describe how each consumer commits offsets to track its progress, either automatically or manually.

2. Explain Offset Commit Mechanisms

Detail auto-commit (periodic, may cause duplicates) vs manual commit (sync/async, gives control). Mention that offsets are stored in the __consumer_offsets topic.

3. Describe Rebalance Triggers and Process

List triggers: consumer join/leave, partition changes, etc. Explain the rebalance phases: group coordinator election, join group, sync group, and partition assignment.

4. Detail What Happens During Rebalance

Explain that consumers stop processing, commit offsets (if possible), revoke partitions, and then receive new assignments. Highlight that commits may fail during rebalance, leading to duplicates or lost messages.

5. Discuss Trade-offs and Best Practices

Cover strategies to minimize rebalance impact: using cooperative rebalancing, tuning session timeouts, and implementing idempotent processing. Mention how this affects delivery semantics.

Key Points to Mention

  • Consumer group coordinator and its role in managing offsets and rebalances
  • Auto-commit vs manual commit: pros, cons, and impact on delivery semantics
  • Rebalance triggers: consumer failure, new consumer, partition changes, etc.
  • Rebalance phases: JoinGroup, SyncGroup, and partition assignment strategies (range, round-robin, sticky, cooperative)
  • During rebalance, consumers cannot commit offsets, which can lead to duplicate processing
  • Best practices: session timeout tuning, static membership, cooperative rebalancing, and idempotent consumers

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How does Kafka handle message ordering, and what does enabling idempotent producers actually give you in terms of exactly-once semantics?

System DesignTechnical Trade-offs
Author's notes

Ordering within a partition is easy to explain.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining Kafka's ordering guarantee within a partition and how partitioning affects global order. Then clarify that idempotent producers ensure exactly-once semantics per partition by deduplicating retries, but true end-to-end exactly-once requires transactional writes and consumer offset management.

Pro tip: Emphasize that idempotence alone doesn't give exactly-once across multiple partitions or topics; you need transactions for that. Also mention that consumers must be configured to read committed messages to avoid duplicates.

1. Explain Kafka's ordering guarantee

Kafka guarantees order within a partition, not across partitions. Messages are appended to a partition in the order they are produced, and consumers read them in that order.

2. Describe how partitioning affects ordering

Producers can specify a key to determine the partition. Messages with the same key go to the same partition, preserving order for that key. Without a key, messages are round-robin distributed, so order is not guaranteed across partitions.

3. Define idempotent producer

An idempotent producer ensures that messages are not duplicated due to retries. It assigns a sequence number to each message and the broker deduplicates based on producer ID and sequence number.

4. Clarify exactly-once semantics

Idempotent producers provide exactly-once semantics per partition for producer retries. However, for end-to-end exactly-once (including consumer processing), you need transactions that atomically write to multiple partitions and commit consumer offsets.

5. Discuss trade-offs and limitations

Enabling idempotence adds overhead but is lightweight. Transactions have higher overhead and require careful configuration. Exactly-once is only guaranteed within Kafka; external systems may need additional mechanisms.

Key Points to Mention

  • Ordering is guaranteed only within a partition, not across partitions.
  • Idempotent producers prevent duplicate messages from retries by using producer IDs and sequence numbers.
  • Exactly-once semantics require transactions to atomically write to multiple partitions and commit offsets.
  • Consumers must set isolation.level to read_committed to avoid reading uncommitted or aborted messages.
  • Idempotence alone does not provide exactly-once across multiple partitions or topics.
  • Trade-offs: idempotence has minimal overhead, transactions have higher latency and throughput impact.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

What strategies do you use to handle backpressure in a Kafka-based pipeline, and how do you tune batch size and compression for throughput?

System DesignTechnical Trade-offs
Author's notes

Talked through linger.ms and batch.size for batching, snappy vs lz4 vs gzip tradeoffs, and consumer lag monitoring as a backpressure signal.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining backpressure in a Kafka pipeline and its causes, then outline a layered strategy covering producer, consumer, and broker-level controls. Explain how you tune batch size and compression based on throughput, latency, and durability trade-offs, using metrics to guide decisions.

Pro tip: Emphasize that backpressure handling is about monitoring and dynamic adjustment, not just static configuration. Mention how you use Kafka consumer lag metrics and producer buffer metrics to trigger autoscaling or throttling.

1. Define backpressure and its impact

Explain what backpressure means in a Kafka pipeline (e.g., producers outpacing consumers, broker overload) and why it matters for system stability and latency.

2. Outline backpressure strategies

Describe producer-side (e.g., throttling, buffering, async sends with callbacks), consumer-side (e.g., pause/resume, manual commit, scaling consumers), and broker-side (e.g., quotas, partition rebalancing) strategies.

3. Explain batch size tuning

Discuss how batch size affects throughput and latency: larger batches improve throughput but increase latency; smaller batches reduce latency but may lower throughput. Mention factors like linger.ms and compression.

4. Explain compression tuning

Compare compression algorithms (e.g., gzip, snappy, lz4, zstd) in terms of compression ratio, CPU overhead, and throughput. Explain how to choose based on workload and hardware.

5. Describe monitoring and iteration

Highlight the importance of metrics (e.g., consumer lag, producer buffer availability, broker CPU) and how you use them to iteratively adjust configurations and scale resources.

Key Points to Mention

  • Producer configurations: batch.size, linger.ms, compression.type, max.in.flight.requests.per.connection, acks
  • Consumer configurations: max.poll.records, fetch.min.bytes, fetch.max.wait.ms, enable.auto.commit, session.timeout.ms
  • Broker configurations: quota enforcement, partition count, replication factor, log segment size
  • Compression trade-offs: zstd for high compression, lz4 for low latency, snappy for balanced
  • Backpressure mechanisms: Kafka consumer pause/resume, reactive streams, rate limiting, autoscaling consumers
  • Monitoring tools: Kafka consumer lag, JMX metrics, Prometheus/Grafana, Confluent Control Center

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q6

Design a system that guarantees at-least-once delivery end-to-end, then explain what changes to achieve exactly-once semantics.

System DesignTechnical Trade-offs
Author's notes

This was the closer and it tied everything together.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and assumptions, then design a system with durable queues, retries, and idempotent consumers to achieve at-least-once delivery. For exactly-once, introduce deduplication, transactional writes, and possibly distributed transactions or idempotent processing with unique message IDs.

Pro tip: Emphasize that exactly-once is often achieved through idempotency and deduplication rather than true distributed transactions, and discuss the trade-offs between latency, complexity, and cost.

1. Clarify Requirements and Assumptions

Ask about scale, latency, message ordering, failure scenarios, and whether exactly-once is truly needed or if at-least-once with idempotency suffices.

2. Design At-Least-Once Delivery

Use durable message queues (e.g., Kafka) with producer acks, consumer manual offset commits, and retries with exponential backoff. Ensure consumers are idempotent or can handle duplicates.

3. Identify Sources of Duplicates

Explain that duplicates arise from producer retries, consumer reprocessing after failure, and network partitions. Highlight the need for deduplication mechanisms.

4. Achieve Exactly-Once Semantics

Implement idempotent consumers using unique message IDs and deduplication stores (e.g., Redis, database). For stronger guarantees, use transactional messaging (e.g., Kafka transactions) or two-phase commit across services.

5. Discuss Trade-offs and Alternatives

Compare at-least-once vs exactly-once in terms of complexity, performance, and cost. Mention that exactly-once often requires idempotency and may not be feasible in all scenarios.

Key Points to Mention

  • Idempotency: ensuring repeated processing of the same message has no additional effect.
  • Deduplication: using unique message IDs and a deduplication store to filter duplicates.
  • Transactional messaging: Kafka transactions or two-phase commit for atomic writes.
  • Consumer offset management: committing offsets only after successful processing.
  • Retry policies: exponential backoff and dead-letter queues for poison messages.
  • Trade-offs: exactly-once adds latency and complexity; at-least-once with idempotency is often sufficient.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.