Transaction

المعاملة (Transaction)

GLS-000094

Intermediatedatabase1 min read
firestore transactionatomic operationdatabase transactionrunTransaction

Definition

A set of database operations that either all succeed or all fail — ensuring data stays consistent.

مجموعة من عمليات قاعدة البيانات إما تنجح كلها أو تفشل كلها — لضمان اتساق البيانات.

Why It Matters

Without transactions, two users creating content simultaneously could get the same canonical ID. Transactions prevent this race condition.

بدون المعاملات، مستخدمان يُنشئان محتوى في وقت واحد قد يحصلان على نفس المعرّف الأساسي. المعاملات تمنع هذا التعارض.

Full Definition

A Firestore transaction reads documents, makes decisions based on their values, then writes updates — all atomically. If any step fails or another process changes the data mid-transaction, Firestore retries automatically. Transactions are used in 404Fault for safe counter increments (e.g., reserving canonical IDs) where concurrent requests must not create duplicate IDs.
معاملة Firestore تقرأ المستندات وتتخذ قرارات بناءً على قيمها ثم تكتب التحديثات — كلها بشكل ذري. إذا فشلت أي خطوة أو غيّرت عملية أخرى البيانات في منتصف المعاملة، يُعيد Firestore المحاولة تلقائيًا. تُستخدم المعاملات في 404Fault لزيادة العدادات بأمان (مثلاً حجز المعرّفات الأساسية) حيث يجب ألا تُنشئ الطلبات المتزامنة معرّفات مكررة.

Example Usage

The glossary seed route uses a transaction to safely increment the _counters/gls document and reserve unique canonicalIds like GLS-000042.

مسار بذر الغلوساري يستخدم معاملة لزيادة مستند _counters/gls بأمان وحجز canonicalIds فريدة مثل GLS-000042.

Knowledge Graph

Avoid these mistakes when using Transaction:

1

Doing heavy async work inside a transaction (transactions should be fast)

2

Not handling transaction failures in your code

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 Transaction.

Explain:
1. What is Transaction and why it matters
2. The core architecture and required tools
3. Step-by-step implementation plan
4. Common mistakes to avoid: Doing heavy async work inside a transaction (transactions should be fast), Not handling transaction failures in your code
5. Best practices and production tips

Official Resources