تمرین ۱ — شمارندهٔ exactly-once روی کافکا و پایگاه دادهExercise 1 — an exactly-once counter on Kafka and a database
checkpoint با کلید (topic,partition) همراه totalها commit میشود؛ epoch مالک در DB و در همان تراکنش بررسی میشود.Checkpoints keyed by (topic,partition) commit with totals; the sink database checks owner epoch within that transaction.
نسخهٔ بازبینیشده برای مصاحبهReviewed interview brief
Kafka با سه partition و click count در DB را طراحی کن. اثر و checkpoint هر topic/partition را در یک تراکنش ذخیره کن؛ last_offset هر کاربر فقط با key-to-partition ثابت معنا دارد. crash، ACK گمشده، rebalance و stale consumer را با fencing و replay منظم تحلیل کن.Count clicks from three Kafka partitions into a database. Commit effects and topic/partition checkpoints together. Explain fixed key routing for per-user offsets, crashes, lost ACKs, ordered replay, rebalances and stale-consumer fencing.
معیار پاسخ خوبWhat a good answer demonstrates
- offset دو partition مقایسه نشدهPartition-scoped offsets
- commit اثر و checkpoint اتمیک استAtomic output/checkpoint
- پرش offset، writer همزمان و rebalance پوشش داده شدهاندOrdering, rebalance and fencing
پیگیری مصاحبه:Interview follow-up: تعداد partitionها تغییر کند و کاربر جابهجا شود؛ dedup key چگونه مهاجرت میکند؟Partition count changes and a user moves. How do you migrate the dedup identity?
آزمایشگاه تکمیلی · زمان تقریبی ۴–۸ ساعتExtended hands-on laboratory · estimated 4–8 hours
تاپیک clicks سه پارتیشن با routing ثابت user_id دارد. جدول click_counts(user_id,total) و consumer_checkpoints(topic,partition,last_offset,owner_epoch) با کلید مرکب بساز. برای هر پارتیشن، سطر checkpoint را در تراکنش قفل کن، epoch را بررسی کن، فقط رکوردهای مرتبِ بعد از last_offset را اعمال کن و totalها و آخرین offset واقعاً پردازششده را با هم commit کن؛ ACK بروکر بعد از commit است. همزمانی دو batch در یک epoch هم باید با قفل/شرط تراکنشی کنترل شود. epoch گروه Kafka خودکار DB را fence نمیکند: انتقال مالکیت باید epoch معتبر را در sink نصب کند. crash، ACK گمشده، replay، مالک کهنه و دو پارتیشن با offset یکسان را بیازما. checkpoint را با TTL حذف نکن؛ نبود تاریخچهٔ لازم یا تغییر routing به cutover، event_id و بازسازی مشخص نیاز دارد.
Use a three-partition clicks topic with fixed user_id routing. Create click_counts(user_id,total) and consumer_checkpoints(topic,partition,last_offset,owner_epoch) with a composite checkpoint key. Lock the partition checkpoint inside a transaction, validate epoch, process ordered records newer than last_offset, and commit totals plus the last actually processed offset together; broker ACK follows commit. Serialize batches even within one epoch. Kafka group epochs do not automatically fence a database: ownership transfer must install a valid epoch at the sink. Test crashes, lost ACKs, replay, stale owners and equal offsets in different partitions. Never expire active checkpoints by TTL; missing history or routing changes require explicit cutover, event IDs and rebuilding.
برای یادگیریِ عمیق است؛ انجام کاملش در زمان بحثِ مصاحبه انتظار نمیرود.The full laboratory is optional depth work and is not expected within the discussion time.
ارزیابی، سطح و شواهد این تمرینAssessment, level and evidence · حل آموزشی این تمرینWorked solution · Kafka 4.1 · design and delivery semantics · AWS · safe retries with idempotent APIs