The Real Fullstack

The Split-Brain Scheduler

There's a distributed lock. Only one node can hold it. So who sent the second invoice?

مهندس أول10 دقيقةمختبر تصحيح الأخطاءمحاكي الخط الزمني
redispostgresqlkuberneteszookeeper

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Predict what A does when it resumes, identify why a lease alone cannot prevent two leaders, and make the storage reject a stale leader.السياق · أهداف التعلّم ▾

Wrenly runs its monthly billing job on two replicas; a Redis lock with a 10-second lease decides who runs it. On 1 December, replica A paused for 14 seconds in garbage collection. Its lease expired, B took over — and then A woke up and carried on.

المهمة: Predict what A does when it resumes, identify why a lease alone cannot prevent two leaders, and make the storage reject a stale leader.

أهداف التعلّم

  • Understand that a process can lose a lease without knowing it.
  • Use fencing tokens so storage rejects stale leaders.
  • Make side effects idempotent with business keys.
المحاكاةمحاكاة
scheduler Ascheduler BRedis lockbilling DB
تشغيل المحاكاة
-- lock service hands out a monotonically increasing token with every lease-- scheduler A: token 41   scheduler B (after expiry): token 42UPDATE billing_runs   SET leader_token = :token, last_batch = :batch WHERE month = '2026-11' AND leader_token <= :token;   -- A (41) is rejected once B (42) has written-- 0 rows updated → you are no longer the leader: stop immediatelyINSERT INTO invoices (customer_id, month, …) VALUES (…)ON CONFLICT (customer_id, month) DO NOTHING;          -- business key: one invoice per customer and month

تبسيط

Two symptoms with deterministic fixes. Consensus systems (etcd, ZooKeeper) provide ordered tokens out of the box. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

مفيد قبل هذا التحدي

تحديات ذات صلة

المراجع