VWhen is Kafka a better fit than a simple message queue?
Senso della risposta✓
Lingua2
Domanda dell’intervistatoreKafka
I colloqui su Kafka di solito partono dal perché esiste e da come si differenzia da una classica coda di messaggi, poi passano a partizioni, consumer group e garanzie di consegna. Molte domande riguardano in realtà che cosa succede quando qualcosa si guasta.
Spiega con un piccolo esempio: un topic chiamato orders, tre partizioni e due consumer. Un'immagine concreta aiuta te e chi ti intervista, e ti impedisce di usare parole vaghe.
- ✓Parole → espressioni → frasi → parlato
- ✓Senso della risposta
- ✓Lingua
Domande comuni e risposte di esempio
When is Kafka a better fit than a simple message queue?
Quando Kafka è più adatto di una semplice coda di messaggi?
Che cosa vuole sentire l'intervistatore. L'idea di un log con possibilità di rilettura, più consumer group e il throughput, insieme a un limite detto con onestà.
Risposta di esempio in inglese da esercitare ad alta voceKafka is a distributed, append-only log. Messages are not removed when they are read. They stay for a configured time, and each consumer group keeps its own position, called an offset. This is useful when several systems need the same events, when I want to replay history, for example after a bug fix, or when throughput is very high. A simple queue like RabbitMQ is often better for task distribution with complex routing, where each message is processed once and then disappears. If the load is small and I do not need replay, a simple queue is easier to run.
How do partitions affect ordering and scaling?
Come influiscono le partizioni sull'ordinamento e sulla scalabilità?
Che cosa vuole sentire l'intervistatore. L'ordine solo dentro una partizione, le chiavi e le partizioni come unità di parallelismo.
Risposta di esempio in inglese da esercitare ad alta voceA topic is split into partitions, and each partition is an ordered log. Kafka guarantees ordering only inside one partition, not across the whole topic. The producer chooses the partition, usually by hashing the message key, so all messages with the same key, for example one customer ID, go to the same partition and stay in order. Partitions are also the unit of parallelism: more partitions allow more consumers to work in parallel. But the number cannot be reduced later, and increasing it changes where new messages with the same key go, so I choose it with growth in mind.
What is a consumer group, and what happens when a consumer fails?
Che cos'è un consumer group e che cosa succede quando un consumer si guasta?
Che cosa vuole sentire l'intervistatore. L'assegnazione delle partizioni, il rebalancing e gli offset di cui è stato fatto il commit.
Risposta di esempio in inglese da esercitare ad alta voceA consumer group is a set of consumers that share the work of a topic. Each partition is assigned to only one consumer in the group, so the group processes the topic in parallel without duplicates. If there are more consumers than partitions, the extra ones stay idle. When a consumer crashes or a new one joins, Kafka rebalances: it reassigns partitions between the members. The new owner continues from the last committed offset. During a rebalance, processing pauses for a moment, so I try to keep processing fast and to avoid long pauses that look like a failure.
What delivery guarantees does Kafka give?
Quali garanzie di consegna offre Kafka?
Che cosa vuole sentire l'intervistatore. At most once (al massimo una volta), at least once (almeno una volta) ed exactly once (esattamente una volta), con le condizioni di ciascuna.
Risposta di esempio in inglese da esercitare ad alta voceIn practice there are three levels. At most once means that a message can be lost but is never repeated. At least once means that it is never lost but can be repeated, and this is the most common setup: I commit the offset only after processing. Exactly once is possible with the idempotent producer and transactions, mainly for flows from Kafka to Kafka. For a producer, I set acks to all and use enough in-sync replicas, so a broker failure does not lose data. Because duplicates can still happen, I make my consumers idempotent.
What is consumer lag, and what do you do when it grows?
Che cos'è il consumer lag e che cosa fai quando cresce?
Che cosa vuole sentire l'intervistatore. Una definizione chiara, un passaggio di diagnosi e diverse possibili soluzioni.
Risposta di esempio in inglese da esercitare ad alta voceConsumer lag is the difference between the latest offset in a partition and the offset the consumer has processed. If it grows, the consumers cannot keep up. First I look at why: is processing slow because of a database call, or did the producer traffic increase? Then I have a few options. I can optimise the processing, add consumers up to the number of partitions, or add partitions if I need more parallelism. I set an alert on lag, because a growing lag is usually the first signal of a problem, long before users complain.
Come pronunciare i termini chiave
- Kafka
- càf-ca
- partition
- par-tìsh-on
- offset
- òf-set
- broker
- bròu-ker
- throughput
- thrù-put
- replica
- rèp-li-ca
Frasi utili per rispondere
- Think of a topic as an append-only log.Immagina un topic come un log in cui si può solo aggiungere.
- Ordering is guaranteed only within a partition.L'ordine è garantito solo all'interno di una partizione.
- We commit the offset after processing.Facciamo il commit dell'offset dopo l'elaborazione.
- The consumer has to be idempotent, because duplicates can happen.Il consumer deve essere idempotente, perché possono verificarsi duplicati.
- It depends on the required guarantees and the throughput.Dipende dalle garanzie richieste e dal throughput.
- In that case I would look at the consumer lag first.In quel caso guarderei prima il consumer lag.
Errori comuni da evitare
- Dire che Kafka garantisce l'ordinamento globale. Garantisce l'ordine solo dentro una partizione.
- Dire "exactly once" senza le condizioni. Cita i producer idempotenti e le transazioni, e ricorda che i consumer devono comunque essere idempotenti.
- Trattare Kafka come un database per tutto. È eccellente per i flussi di eventi, quindi di' che cosa conservi altrove.
- Non parlare mai dei guasti. Spiega che cosa succede quando un broker o un consumer va giù.
Domande frequenti
Devo conoscere il funzionamento interno di Kafka per un normale colloquio backend?
Serve il modello: topic, partizioni, offset, consumer group e garanzie di consegna. Gli aspetti interni, come il controller o i segmenti del log, servono per i ruoli specialistici.
Quali strumenti o versioni devo citare?
Di' che cosa hai usato: la libreria client, come monitoravi il lag e se usavi uno schema registry. I dettagli onesti contano più dei numeri di versione.
Come posso esercitarmi a spiegare Kafka senza appunti?
Disegna un piccolo esempio di topic con tre partizioni e racconta che cosa succede quando arriva un messaggio, quando un consumer si guasta e quando aggiungi un consumer. Ripeti ad alta voce finché il racconto dura circa un minuto.
Leggere una risposta non è la stessa cosa che dirla. Esercita ogni domanda ad alta voce, poi confronta il significato e la lingua della tua risposta.
Prova SpeakRole ↗Altri argomenti in quest’area