VWhen is Kafka a better fit than a simple message queue?
سؤال المقابلKafka
تبدأ مقابلات Kafka عادةً بسؤال عن سبب وجودها وبماذا تختلف عن قائمة انتظار الرسائل التقليدية، ثم تنتقل إلى الأقسام ومجموعات المستهلكين وضمانات التسليم. وكثير من الأسئلة هي في الحقيقة عما يحدث عند الفشل.
اشرح بمثال صغير: موضوع (topic) اسمه orders، وثلاثة أقسام ومستهلكان. الصورة الملموسة تساعدك وتساعد المحاور، وتمنعك من استخدام كلمات غامضة.
- ✓كلمات → عبارات → جمل → تحدث
- ✓معنى الإجابة
- ✓اللغة
أكثر الأسئلة تكرارًا ونماذج الإجابات
When is Kafka a better fit than a simple message queue?
متى تكون Kafka أنسب من قائمة انتظار رسائل بسيطة؟
ما الذي يريد المحاور سماعه. فكرة السجل مع إمكانية إعادة القراءة، ومجموعات المستهلكين المتعددة، والإنتاجية، وحدّ صريح لاستخدامها.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍKafka 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?
كيف تؤثر الأقسام (partitions) في الترتيب والتوسّع؟
ما الذي يريد المحاور سماعه. الترتيب داخل القسم فقط، والمفاتيح (keys)، والأقسام بوصفها وحدة التوازي.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍA 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?
ما مجموعة المستهلكين (consumer group)، وماذا يحدث عندما يفشل أحد المستهلكين؟
ما الذي يريد المحاور سماعه. إسناد الأقسام، وإعادة التوازن (rebalancing)، والإزاحات المُثبَّتة (committed offsets).
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍA 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?
ما ضمانات التسليم التي تقدمها Kafka؟
ما الذي يريد المحاور سماعه. مرة واحدة على الأكثر، ومرة واحدة على الأقل، ومرة واحدة بالضبط، مع شروط كل ضمان.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍIn 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?
ما تأخر المستهلك (consumer lag)، وماذا تفعل عندما يزداد؟
ما الذي يريد المحاور سماعه. تعريف واضح، وخطوة تشخيص أولى، وعدة حلول ممكنة للمعالجة.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍConsumer 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.
كيف تنطق المصطلحات الأساسية
- Kafka
- كَافْكَا
- partition
- بَارْتِشِن
- offset
- أُوفْسِت
- broker
- بْرُوكِر
- throughput
- ثْرُوبُوت
- replica
- رِبْلِكَا
عبارات مفيدة للإجابة
- Think of a topic as an append-only log.تخيّل الموضوع (topic) على أنه سجل لا يُضاف إليه إلا في نهايته (append-only).
- Ordering is guaranteed only within a partition.الترتيب مضمون داخل القسم الواحد فقط.
- We commit the offset after processing.نثبّت الإزاحة (offset) بعد المعالجة.
- The consumer has to be idempotent, because duplicates can happen.يجب أن يكون المستهلك idempotent (لا يتأثر بتكرار المعالجة)، لأن الرسائل المكررة واردة.
- It depends on the required guarantees and the throughput.هذا يعتمد على الضمانات المطلوبة ومعدل الإنتاجية.
- In that case I would look at the consumer lag first.في هذه الحالة سأنظر أولًا إلى تأخر المستهلكين (consumer lag).
أخطاء شائعة
- القول إن Kafka تضمن الترتيب العام. هي تضمن الترتيب داخل القسم الواحد فقط.
- قول «مرة واحدة بالضبط (exactly once)» دون ذكر الشروط. اذكر المنتِج idempotent producer والمعاملات (transactions)، وأن على المستهلكين أن يكونوا idempotent مع ذلك.
- اعتبار Kafka قاعدة بيانات لكل شيء. هي ممتازة لتدفقات الأحداث، فقل ما الذي تخزّنه في مكان آخر.
- عدم ذكر الأعطال إطلاقًا. اشرح ما يحدث عندما يتوقف وسيط (broker) أو مستهلك.
الأسئلة الشائعة
هل أحتاج إلى معرفة البنية الداخلية لـ Kafka في مقابلة backend عادية؟
تحتاج إلى النموذج: المواضيع (topics) والأقسام والإزاحات ومجموعات المستهلكين وضمانات التسليم. أما التفاصيل الداخلية مثل المتحكم (controller) أو مقاطع السجل (log segments) فهي للوظائف المتخصصة.
أي الأدوات أو الإصدارات أذكر؟
قل ما استخدمته: مكتبة العميل، وكيف راقبت التأخر (lag)، وهل استخدمت سجل المخططات (schema registry). التفاصيل الصادقة أهم من أرقام الإصدارات.
كيف أتدرب على شرح Kafka دون ملاحظات؟
ارسم مثالًا صغيرًا لموضوع بثلاثة أقسام، وقل ما يحدث عند وصول رسالة، وعند فشل مستهلك، وعند إضافة مستهلك. كرر ذلك بصوت عالٍ حتى يستغرق نحو دقيقة.
قراءة الإجابة ليست مثل قولها. تدرّب على كل سؤال بصوت عالٍ، ثم قارن معنى إجابتك ولغتها بالنموذج.
جرّب SpeakRole ↗موضوعات أخرى في هذا المجال