VWhen is Kafka a better fit than a simple message queue?
Pytanie rekruteraKafka
Rozmowy o Kafkę zwykle zaczynają się od pytania, po co ona istnieje i czym różni się od klasycznej kolejki komunikatów, a potem przechodzą do partycji, grup konsumentów i gwarancji dostarczania. Wiele pytań dotyczy tak naprawdę tego, co się dzieje, gdy coś zawiedzie.
Wyjaśniaj na małym przykładzie: topic o nazwie orders, trzy partycje i dwóch konsumentów. Konkretny obraz pomaga i tobie, i rekruterowi, a przy okazji chroni przed mglistymi sformułowaniami.
- ✓Słowa → zwroty → zdania → mówienie
- ✓Sens odpowiedzi
- ✓Język
Częste pytania i przykładowe odpowiedzi
When is Kafka a better fit than a simple message queue?
Kiedy Kafka sprawdza się lepiej niż zwykła kolejka komunikatów?
Co chce usłyszeć rekruter. Idea logu z możliwością odtwarzania, wiele grup konsumentów, przepustowość i uczciwe ograniczenie.
Przykładowa odpowiedź po angielsku do ćwiczenia na głosKafka 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?
Jak partycje wpływają na kolejność i skalowanie?
Co chce usłyszeć rekruter. Kolejność tylko w obrębie partycji, klucze i partycje jako jednostka równoległości.
Przykładowa odpowiedź po angielsku do ćwiczenia na głosA 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?
Czym jest grupa konsumentów (consumer group) i co się dzieje, gdy konsument ulegnie awarii?
Co chce usłyszeć rekruter. Przydział partycji, rebalansowanie i zatwierdzone offsety.
Przykładowa odpowiedź po angielsku do ćwiczenia na głosA 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?
Jakie gwarancje dostarczania daje Kafka?
Co chce usłyszeć rekruter. Co najwyżej raz, co najmniej raz i dokładnie raz, wraz z warunkami dla każdej z nich.
Przykładowa odpowiedź po angielsku do ćwiczenia na głosIn 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?
Czym jest opóźnienie konsumenta (consumer lag) i co robić, gdy rośnie?
Co chce usłyszeć rekruter. Jasna definicja, krok diagnostyczny i kilka możliwych napraw.
Przykładowa odpowiedź po angielsku do ćwiczenia na głosConsumer 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.
Jak wymawiać kluczowe terminy
- Kafka
- KAF-ka
- partition
- par-TISZ-n
- offset
- OF-set
- broker
- BROŁ-ker
- throughput
- TRU-put (th jak w „think”)
- replica
- REP-li-ka
Przydatne zwroty do odpowiedzi
- Think of a topic as an append-only log.Można myśleć o topicu jak o logu, do którego tylko się dopisuje.
- Ordering is guaranteed only within a partition.Kolejność jest gwarantowana tylko w obrębie partycji.
- We commit the offset after processing.Offset zatwierdzamy po przetworzeniu.
- The consumer has to be idempotent, because duplicates can happen.Konsument musi być idempotentny, bo duplikaty mogą się zdarzyć.
- It depends on the required guarantees and the throughput.To zależy od wymaganych gwarancji i przepustowości.
- In that case I would look at the consumer lag first.W takim przypadku najpierw sprawdzę consumer lag.
Typowe błędy
- Twierdzenie, że Kafka gwarantuje globalną kolejność. Gwarantuje kolejność tylko w obrębie partycji.
- Mówienie „dokładnie raz” bez warunków. Wspomnij o idempotentnych producentach i transakcjach oraz o tym, że konsumenci i tak powinni być idempotentni.
- Traktowanie Kafki jak bazy danych do wszystkiego. Świetnie nadaje się do strumieni zdarzeń, więc powiedz, co przechowujesz gdzie indziej.
- Niewspominanie o awariach. Wyjaśnij, co się dzieje, gdy padnie broker lub konsument.
Najczęstsze pytania
Czy na zwykłej rozmowie backendowej trzeba znać wnętrze Kafki?
Potrzebny jest model: topiki, partycje, offsety, grupy konsumentów i gwarancje dostarczania. Elementy wewnętrzne, takie jak kontroler czy segmenty logu, są potrzebne na stanowiskach specjalistycznych.
Jakie narzędzia lub wersje warto wymienić?
Powiedz, jak wyglądało to w twojej pracy: biblioteka kliencka, monitorowanie opóźnienia konsumenta i ewentualny schema registry. Szczere szczegóły są ważniejsze niż numery wersji.
Jak ćwiczyć wyjaśnianie Kafki bez notatek?
Narysuj jeden mały przykład topicu z trzema partycjami i opowiedz, co się dzieje, gdy przychodzi wiadomość, gdy konsument ulega awarii i gdy dodajesz konsumenta. Powtarzaj na głos, aż opowieść zajmie około minuty.
Przeczytać odpowiedź to nie to samo, co ją wypowiedzieć. Przećwicz każde pytanie na głos, a potem porównaj sens i język własnej odpowiedzi.
Wypróbuj SpeakRole ↗Inne tematy w tym obszarze