Idempotency

الاتساق الذاتي (Idempotency)

Intermediatebackend1 min read
idempotentidempotent operationsafe to retrydeduplication

Definition

A property where performing the same operation multiple times produces the same result as doing it once.

خاصية يُنتج فيها تنفيذ نفس العملية عدة مرات نفس النتيجة التي ينتجها تنفيذها مرة واحدة.

Why It Matters

All 404Fault glossary seed operations are idempotent — they check for existing slugs before inserting. This means you can re-run seeds after a crash without creating duplicates.

جميع عمليات بذر قاموس 404Fault اتساقية ذاتيًا — تتحقق من الـslugs الموجودة قبل الإدراج. هذا يعني إمكانية إعادة تشغيل البذر بعد التعطل دون إنشاء تكرارات.

Full Definition

An idempotent operation can be applied multiple times and always produces the same result. GET and DELETE HTTP methods are idempotent; POST is not by default. Database upserts (`set({ merge: true })`) are idempotent. In 404Fault's glossary seeding, idempotency means: if the seed runs twice, no duplicate terms appear. The seed checks for existing slugs before inserting. This is critical for retryable operations.
العملية الاتساقية يمكن تطبيقها عدة مرات وتُنتج دائمًا نفس النتيجة. أساليب HTTP GET وDELETE اتساقية ذاتيًا؛ POST ليس كذلك افتراضيًا. في بذر مصطلحات 404Fault، الاتساق الذاتي يعني: إذا عمل البذر مرتين، لا تظهر مصطلحات مكررة.

Example Usage

// Idempotent seed pattern: const existing = await db.collection('glossary').where('slug', 'in', slugs).get(); const existingSlugs = new Set(existing.docs.map(d => d.data().slug)); const toSeed = terms.filter(t => !existingSlugs.has(t.slug));

// نمط البذر الاتساقي: const existing = await db.collection('glossary').where('slug', 'in', slugs).get(); const existingSlugs = new Set(existing.docs.map(d => d.data().slug)); const toSeed = terms.filter(t => !existingSlugs.has(t.slug));

Knowledge Graph

Avoid these mistakes when using Idempotency:

1

Not checking for existing records before insert — duplicates corrupt data

2

Treating all POST endpoints as idempotent when they're not — Stripe charge endpoints create new charges on each call

Sign in to unlock guided AI explanations from AI Teacher.

Generate a Prompt

Copy this prompt and use it directly with any AI model — no setup needed.

Ready-to-Use Prompt
Help me build a project using Idempotency.

Explain:
1. What is Idempotency and why it matters
2. The core architecture and required tools
3. Step-by-step implementation plan
4. Common mistakes to avoid: Not checking for existing records before insert — duplicates corrupt data, Treating all POST endpoints as idempotent when they're not — Stripe charge endpoints create new charges on each call
5. Best practices and production tips

Official Resources