DDIA·واژه‌هاTERMS

نقشه راهRoadmap/ واژه‌نامهGlossary/ فصل ۱Chapter 1

۱1انتخاب‌ها و هزینه‌های معماری سیستم‌های دادهTrade-offs in data systems architecture

۲۰ واژه از فصل ۱ — هر کدام با یک مثال روزمره، یک نمودار و تلهٔ رایج.20 terms from chapter 1, each with an everyday example, a diagram and the usual trap.

backup and restore

پشتیبان‌گیری و بازیابی فصل ۱Chapter 1 · دیدن در متنsee in context همچنینalso in فصل ۲ch 2

آخرین بار بازیابی را امتحان کردی؟When did you last test a restore?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

از عکس‌های گوشی‌ات نسخهٔ پشتیبان داری، ولی هیچ‌وقت آن را روی یک گوشی خالی برنگردانده‌ای. روزی که گوشی گم شود، تازه می‌فهمی فایل‌ها باز می‌شوند یا نه. پشتیبان‌گیری نصف کار است؛ بازیابی نصف دیگر.You keep a backup of your phone photos but have never restored it onto an empty phone. The day the phone is lost is the day you find out whether the files open. Backing up is half the job; restoring is the other half.

تشبیه و تصویر ذهنیThe analogy

کلید یدکی خانه را پیش همسایه می‌گذاری. تا وقتی قفل عوض نشده، آن کلید یک راه نجات است؛ روزی که قفل را عوض کنی و یادت برود، همان کلید تکه فلزی است که هیچ دری را باز نمی‌کند. پشتیبان هم همین است: تا وقتی برگرداندنش را تمرین نکرده‌ای، یک فایل داری، نه یک راه نجات. هر چند وقت یک بار با همان کلید در را باز کن و ببین باز می‌شود.You leave a spare key with the neighbour. As long as the lock is unchanged, that key is a way back in; the day you change the lock and forget, it is a piece of metal that opens nothing. A backup is the same: until you have practised the restore, you own a file, not a way back. Every so often, open the door with that key and check that it turns.

پشتیبانBackupساعت ۲ بامداد2 a.m.خرابیDamageحذف اشتباهیa wrong deleteبازیابیRestoreروی محیط تازهonto a fresh oneبررسیCheckشمارش ردیف‌هاcount the rows
پشتیبان فقط نصف ماجراست؛ نصف دیگر، برگرداندن روی محیطی تازه و شمردن ردیف‌هاست.A backup is only half the story; the other half is restoring onto a fresh machine and counting rows.

و بعدش، فنیAnd now, technically

پشتیبان یک کپی در نقطهٔ زمانی است که عمداً از اصل جدا نگه داشته می‌شود: دیسک دیگر، حساب دیگر، منطقهٔ دیگر. بازیابی یعنی همان کپی را بخوانی و ساختار را از نو بسازی. تفاوت مهمش با replication این است که replica وفادارانه همه چیز را کپی می‌کند — از جمله حذف اشتباهی و خرابی داده — ولی پشتیبان تاریخ را نگه می‌دارد. سه سؤال تعیین‌کننده‌اند: چه چیزی را نگه می‌داری، هر چند وقت یک بار، و چقدر طول می‌کشد تا برگردی. سؤال دوم و سوم همان RPO و RTO را می‌سازند. پشتیبان باید رمزگذاری‌شده و کلیدش جای دیگری باشد، وگرنه یک فایل داری که نمی‌توانی بازش کنی؛ و اگر کپی را روی همان دیسکی بگذاری که داده رویش است، خرابی دیسک هر دو را می‌برد.A backup is a point-in-time copy deliberately kept apart from the original: another disk, another account, another region. Restoring means reading that copy and rebuilding the structure. The important difference from replication is that a replica faithfully copies everything — including the wrong delete and the corrupted page — while a backup keeps history. Three questions decide the design: what you keep, how often, and how long a restore takes. The last two produce your RPO and RTO. A backup also has to be encrypted with its key stored elsewhere, or you own a file you cannot open, and if the copy sits on the same disk as the data one disk failure takes both.

RPOچقدر داده را می‌توانی از دست بدهیhow much data you can afford to lose
RTOچقدر طول بکشد تا سیستم برگرددhow long it may take to come back
1 بار در فصلحداقل تمرین واقعی بازیابیthe least you should practise a restore

تلهٔ رایجThe usual trap

پشتیبانی که هرگز بازیابی نشده. باگ پشتیبان‌گیری تا روز بازیابی معلوم نمی‌شود: فایل ناقص، کلید گم‌شده، یا نسخهٔ اشتباه دیتابیس. تا وقتی restore را در یک محیط واقعی تمرین نکرده‌ای، امید داری، نه پشتیبان.A backup nobody ever restored. Backup bugs surface only on restore day: a truncated file, a lost key, a dump from the wrong database version. Until a restore has run in a real environment you have hope, not a backup.

change data capture

ثبت تغییر داده فصل ۱Chapter 1 · دیدن در متنsee in context همچنینalso in فصل ۱۲ch 12

چطور بقیه بفهمند چیزی عوض شده، بی‌آنکه دو بار بنویسی؟How do other systems learn a row changed, without a second write?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

معلم نمره‌ها را در دفتر خودش می‌نویسد و همان لحظه باید کارنامهٔ والدین، تابلوی کلاس و سامانهٔ مدرسه هم به‌روز شوند. اگر خودش هر سه را جدا بنویسد، دیر یا زود یکی جا می‌ماند یا با بقیه نمی‌خواند؛ راه ساده‌تر این است که هر نمره، همان وقت که در دفتر می‌نشیند، روی یک برگ کاربن هم بیفتد. ثبت تغییر داده (CDC) همین برگ کاربن است: تغییر یک جا نوشته می‌شود و بقیه از روی نسخهٔ آن می‌خوانند.Your teacher writes the marks in his own register, and the parents' report, the classroom board and the school system all have to update at the same moment. If he writes all three himself, one is always behind. Change data capture is the carbon sheet under that register: the change is recorded once and everyone else reads the copy.

تشبیه و تصویر ذهنیThe analogy

خبرگزاری کوچکی را تصور کن که یک سند مشترک دارد. خبرنگار هر خط تازه را همان‌جا می‌نویسد و رادیو، سایت و روزنامهٔ صبح همه همان سند را دنبال می‌کنند؛ هیچ‌کدام نسخهٔ خودش را ندارد. مزیتش این است که یک خبر فقط یک بار نوشته می‌شود و هر سه با هم به‌روز می‌شوند. بهایش این است که هر سه کمی عقب‌ترند — چند ثانیه یا چند دقیقه — و اگر کسی سند را در فایل خودش کپی کند، تصحیح‌های بعدی دیگر به او نمی‌رسد. روز اول هم هر کدام مجبورند کل آرشیو را یک بار بخوانند تا از جای درست شروع کنند.Picture a small news agency with one shared document. The reporter writes each new line there, and the radio, the website and the morning paper all follow that document; none of them keeps its own copy. The gain is that a story is written once and all three update together. The price is that all three trail slightly behind — seconds or minutes — and anyone who copies the document into his own file stops receiving corrections. On day one each of them also has to read the whole archive to start in the right place.

کامیتCommitدیتابیسdatabaseلاگ تغییراتChange logWAL یا binlogWAL or binlogخوانندهٔ لاگLog readerترتیب حفظ می‌شودkeeps orderرویداد در صفEvent on a queueممکن است تکراریmay repeatایندکس و کشIndex and cacheمشتق و تازهderived, fresh
تغییر فقط یک جا نوشته می‌شود؛ بقیه به‌جای حدس زدن، از لاگ می‌خوانند.The change is written once; everyone else reads it from the log instead of guessing.

و بعدش، فنیAnd now, technically

CDC لاگ تغییرات خودِ دیتابیس را می‌خواند؛ همان چیزی که موتور پیش از اعمال نوشتن روی دیسک ثبت می‌کند — WAL در پستگرس، binlog در MySQL. هر رکورد لاگ می‌گوید کدام ردیف، کدام ستون‌ها و با چه ترتیبی عوض شد، پس یک خواننده می‌تواند همان ترتیب را نگه دارد و هر تغییر را به یک رویداد تبدیل کند. چرا این از کوئری زدن بهتر است؟ چون کوئری «هر ردیفی که updated_at تازه دارد» هر بار بخش بزرگی از جدول را می‌گردد و حذف‌ها را هم نمی‌بیند، مگر اینکه حذف نرم بگذاری. لاگ حذف را هم دارد. اما هیچ‌چیز مجانی نیست: خواننده باید یک بار کل داده را به‌عنوان snapshot بخواند و بعد به لاگ وصل شود، وگرنه تغییرهای بین این دو را از دست می‌دهد. اگر خواننده عقب بیفتد، دیتابیس لاگ را نگه می‌دارد و در بدترین حالت دیسک پر می‌شود. تحویل هم دقیقاً یک بار نیست: ممکن است یک رویداد دو بار برسد، پس مصرف‌کننده باید با یک کلید یکتا تکراری‌ها را دور بریزد.CDC reads the database's own change log: the record the engine writes before it touches the data, such as the WAL in Postgres or the binlog in MySQL. Each log record says which row, which columns and in what order changed, so a reader can preserve that order and turn each change into an event. Why is that better than polling? Because a query for rows with a fresh updated_at re-reads a large slice of the table every time and cannot see deletes unless you keep a soft-delete column. The log sees the delete. Nothing is free, though: the reader must first take a full snapshot and then attach to the log, or it loses everything in between. If the reader falls behind, the database holds the log for it, and in the worst case the disk fills up. Delivery is not exactly-once either: an event may arrive twice, so the consumer needs a unique key to drop duplicates.

1 لاگهمهٔ تغییرها از یک لاگ مرتب می‌آیندall changes arrive from one ordered log
at-least-onceرویداد ممکن است تکراری برسد، پس مصرف‌کننده باید idempotent باشدevents may repeat, so consumers must be idempotent
1 snapshotیک بار کل داده را می‌خوانی، بعد از لاگ ادامه می‌دهیone full copy first, then follow the log

چرا کوئری‌زدن روی updated_at جواب نمی‌دهدWhy polling updated_at fails

اولین نسخه‌ای که همه می‌نویسند یک job است که هر دقیقه یک بار جدول را برای ردیف‌های تازه می‌گردد. این کار دو مشکل دارد. اول، با بزرگ شدن جدول گران‌تر می‌شود، چون باید ایندکس روی updated_at را از آخر بخواند و آن ایندکس هم با هر نوشتن تازه می‌شود. دوم و مهم‌تر، حذف را نمی‌بیند: ردیف پاک شده و updated_at هم با خودش رفته است، پس سیستم مقصد تا ابد فکر می‌کند آن ردیف وجود دارد. لاگ این دو مشکل را ندارد، ولی به جایش یک قرارداد می‌خواهد: ترتیب رویدادها معنا دارد و شروع کار با یک snapshot کامل است.The first version everyone writes is a job that scans the table for new rows every minute. It has two problems. As the table grows it gets more expensive, because it walks the index on updated_at from the end, and that index is itself rewritten on every write. Worse, it cannot see deletes: the row is gone and its updated_at went with it, so the target system believes the row exists forever. A log has neither problem, but it asks for a contract: event order means something, and the job starts from a complete snapshot.

واقعاً کجا می‌شکندWhere it actually breaks

سه جا. یکی وقتی خواننده عقب می‌افتد: در پستگرس، slot بدون مصرف‌کننده WAL را نگه می‌دارد و دیسک پر می‌شود، و این خطا روی دیتابیس اصلی می‌نشیند، نه روی سیستم مقصد. دوم، وقتی schema عوض می‌شود: مصرف‌کننده‌ای که فقط نام و ایمیل را می‌شناخت، ستون تازه را نمی‌فهمد، یا بدتر، معنی ستون عوض‌شده را ندارد. سوم، ترتیب بین دو دیتابیس: CDC فقط داخل یک لاگ ترتیب دارد؛ اگر دو سیستم جدا تغییر می‌کنند، هیچ‌کس ترتیب بین آن‌ها را تضمین نمی‌کند. پس ترتیب را همان‌جایی بساز که می‌توانی، یعنی داخل یک دیتابیس.In three places. When the reader falls behind: in Postgres an unconsumed slot holds the WAL and the disk fills, and that failure lands on the primary database, not on the consumer. When the schema changes: a consumer that only knew name and email cannot make sense of a new column, or worse, does not know that an old column changed meaning. And ordering across two databases: a log is ordered only inside itself, so when two systems change independently nobody guarantees their mutual order. Build order where you can — inside one database.

تلهٔ رایجThe usual trap

این‌که CDC را جایگزین idempotency بگیری. تحویل معمولاً at-least-once است؛ اگر مصرف‌کننده پیام تکراری را دوباره اعمال کند، موجودی انبار یک عدد کم می‌شود و هیچ خطایی هم بالا نمی‌آید. تکراری‌ها را با کلید رویداد یا کلید کسب‌وکار دور بریز، نه با «احتمالاً نمی‌رسد».Treating CDC as a replacement for idempotency. Delivery is usually at-least-once; if a consumer applies a repeated message, stock drops by one more and nothing raises an error. Drop duplicates on an event or business key, not on the hope that the broker will behave.

crypto-shredding

پاک‌سازی با کلید فصل ۱Chapter 1 · دیدن در متنsee in context

چطور چیزی را پاک کنی که هزار نسخه دارد؟How do you erase something that exists in a thousand copies?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

خاطراتت را با خط رمزی خودت نوشته‌ای و معنای علامت‌ها روی یک تکه کاغذ در جیبت است. از آن دفتر چند کپی هم توی کشوی مادرت مانده. برای اینکه دیگر خواندنی نباشد لازم نیست همهٔ کپی‌ها را پیدا کنی؛ همان تکه کاغذ را بسوزان تا همهٔ نسخه‌ها یک‌جا خاموش شوند.You wrote your diary in a code of your own, and the key to it is a scrap of paper in your pocket. Copies of that diary also sit in your mother's drawer. To make it unreadable you do not have to find every copy; burn the scrap and every version goes dark at once.

تشبیه و تصویر ذهنیThe analogy

همین دفتر را بزرگ کن: هزار برگ، چند کپی، و یک کلید که مال یک نفر است. سه چیز را با هم می‌خری. سرعت: یک کار کوچک و همهٔ نسخه‌ها ناخوانا می‌شوند، حتی نسخه‌ای که نمی‌دانی کجاست. برگشت‌ناپذیری: وقتی کلید رفت، داده برای همیشه رفته؛ پس اگر نسخه‌ای از کلید جای دیگری بماند، پاک‌سازی انجام نشده و تو خیال کرده‌ای انجام شده. دانه‌بندی: اگر یک کلید برای همهٔ دفترها باشد، سوزاندنش خاطرات بقیه را هم می‌سوزاند، پس هر رکورد کلید خودش را می‌خواهد.Scale the diary up: a thousand pages, several copies, and one key that belongs to one person. You buy three things at once. Speed: one small act and every copy is unreadable, including the copy whose location you do not know. No way back: once the key is gone the data is gone for good, so if a copy of that key survives anywhere, the erasure did not happen and you only believe it did. Granularity: one key shared by every diary means burning it destroys everyone else's notes too, so each record needs its own key.

حذف از هر نسخهDelete from every copyهر نسخه را جدا پیدا کنfind every copyیکی همیشه جا می‌ماندone always survivesساعت‌ها کار و ریسکhours of work and riskدور انداختن کلیدDiscard the keyیک عمل کوچکone small actهمه با هم ناخواناall dark at onceبرگشت‌ناپذیرno way back
داده سر جایش می‌ماند و نسخه‌ها هم کم نمی‌شوند؛ فقط کلید می‌رود و همهٔ کپی‌ها با هم ناخوانا می‌شوند.The data stays put and no copy is removed; only the key leaves, and every copy goes dark together.

و بعدش، فنیAnd now, technically

در ذخیره‌سازی فقط-افزودنی، حذف یک رکورد عملاً یعنی گشتن در همهٔ نسخه‌ها: SSTableها، لاگ‌ها، پشتیبان‌ها و replicaها. پاک‌سازی با کلید این کار را به یک عمل کوچک تبدیل می‌کند: هر رکورد یا هر مستأجر با کلید دادهٔ خودش رمز می‌شود و «حذف» یعنی دور انداختن همان کلید. دادهٔ رمزشده سر جایش می‌ماند و هیچ بایتی جابه‌جا نمی‌شود، ولی بدون کلید فقط نویز است. کلیدها در یک key store جدا با دسترسی باریک و نسخهٔ پشتیبان رمزگذاری‌شده نگه داشته می‌شوند و همان‌جا هم باید حذف شوند. دوام این حذف به سه چیز بند است: کلید در حافظهٔ پروسه یا کش صفحه نمانده باشد، از همهٔ replicaهای key store پاک شده باشد، و هیچ نسخهٔ رمزگشایی‌شده‌ای بیرون نرفته باشد — گزارش، خروجی تحلیلی، فایل تست.In append-only, log-structured storage, deleting one record means visiting every copy: SSTables, logs, backups, replicas. Crypto-shredding turns that into one small act: each record or each tenant is encrypted under its own data key, and “delete” means discarding that key. The ciphertext stays where it is, not a byte moves, and without the key it is just noise. The keys live in a separate key store with narrow access and an encrypted backup, and they must be deleted there too. The durability of that deletion rests on three things: the key is gone from process memory and the page cache, it is gone from every replica of the key store, and no decrypted copy — a report, an analytics export, a test fixture — ever left the system.

1 کلیدهر رکورد یا هر مستأجر کلید خودش را داردeach record or tenant carries its own key
0 بایتداده جابه‌جا نمی‌شود؛ فقط کلید دور انداخته می‌شودno data moves; only the key is discarded
∞ کپیهر تعداد نسخه، همه با یک کلید ناخوانا می‌شوندany number of copies goes dark with one key

تلهٔ رایجThe usual trap

یک کلید برای همه. اگر کلید مشترک باشد، برای پاک‌کردن یک نفر باید دادهٔ همه را ناخوانا کنی، پس در عمل کلید را نگه می‌داری و حذف هرگز انجام نمی‌شود. و کلید باید از نسخهٔ پشتیبان خودش هم پاک شود؛ وگرنه دادهٔ رمزشده سر جایش است و کلید هم در بکاپ key store، و تو فقط فکر می‌کنی پاک کرده‌ای.One key for everyone. If the key is shared, erasing one person means making everyone's data unreadable, so in practice you keep the key and the deletion never happens. And that key must also be removed from its own backup, or the ciphertext sits there and the key sits in the key-store backup, and you merely believe you deleted something.

همه‌چیز را همان‌طور که رسیده بریزی، بعد بفهمی چیست؟Dump everything as it arrives and work out what it is later?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

کارتن‌های اسباب‌کشی را بازنکرده در انباری چیده‌ای. تا وقتی روی هر کارتن نوشته باشی «کتاب» یا «ظرف»، هر وقت چیزی لازم شد سراغش می‌روی و همان موقع بازش می‌کنی؛ روزی که برچسب نزنی، انباری پر از کارتن بی‌برچسب می‌شود و هیچ‌چیز پیدا نمی‌شود. دریاچهٔ داده هم داده را همان‌طور که رسیده نگه می‌دارد و ساختار را وقت خواندن می‌سازد.You stacked the moving boxes in the storeroom unopened. As long as each box says “books” or “dishes” on the side, you go to it when you need something and open it right then; the day you stop labelling, the storeroom is a wall of identical boxes and nothing can be found. A data lake keeps data exactly as it arrived and builds the structure at read time.

تشبیه و تصویر ذهنیThe analogy

انبار دادهٔ کلاسیک را با این انباری مقایسه کن. انبار داده قفسه‌ای است که هر قلم را قبل از چیدن برچسب می‌زنی؛ گران است، ولی هر کسی وارد شود می‌داند ماست کجاست. دریاچه جایی است که کارتن‌ها را همان‌طور که رسیده می‌گذاری و ساختار را بعداً، وقت پرسیدن سؤال، رویشان می‌کشی. سودش این است که هیچ‌چیز را از دست نمی‌دهی: داده‌ای که امروز به کار نمی‌آید، سال بعد به سؤالی جواب می‌دهد که هنوز نپرسیده‌ای. بهایش این است که کیفیت را نمی‌توانی تضمین کنی؛ فایل ناقص و تکراری و بی‌فهرست می‌رسد و تازه موقع خواندن می‌فهمی.Compare the classic warehouse with that storeroom. A warehouse is a shelf where you label each item before it goes in: expensive, but anyone who walks in knows where the yoghurt is. A lake is where you put the boxes down as they arrived and lay the structure over them later, when a question comes. The gain is that you lose nothing: data that is useless today answers a question next year that you have not asked yet. The price is that quality is not guaranteed — files arrive incomplete, duplicated and unlabelled, and you find out at read time.

فایل خام می‌رسدRaw files arriveبدون schemano schemaذخیره روی آبجکتObject storageارزان و بزرگcheap and bigفهرست و قالبCatalog and formatروی همان فایل‌هاover the same filesپرس‌وجو با ساختارQuery with schemaوقت خواندنat read time
داده همان‌طور که رسیده می‌نشیند و ساختار تازه وقت خواندن رویش می‌آید؛ کیفیت را باید جای دیگری تضمین کنی.Data lands as it arrived and structure only comes at read time; quality has to be enforced somewhere else.

و بعدش، فنیAnd now, technically

دریاچهٔ داده یک فضای ذخیره‌سازی مرکزی است، معمولاً روی object storage، که داده در قالب اصلی خودش در آن می‌نشیند: لاگ JSON، CSV، Parquet. هیچ schema‌ای هنگام نوشتن تحمیل نمی‌شود و ساختار موقع خواندن اعمال می‌شود؛ به همین دلیل به آن schema-on-read می‌گویند، در برابر schema-on-write انبار داده. این کار تولیدکننده و مصرف‌کننده را جدا می‌کند: تیم اپ فقط فایل را می‌ریزد و تیم تحلیل بعداً تصمیم می‌گیرد چه بسازد. هزینه‌ها جای دیگری است. بدون تراکنش، خواننده ممکن است فایل نیمه‌نوشته ببیند. بدون catalog، هیچ‌کس نمی‌داند چه چیزی آنجاست. راه‌حل امروزی، قالب جدولی روی همان object storage است که فهرست و تراکنش سبک اضافه می‌کند و لایهٔ lakehouse را می‌سازد.A data lake is a central store, usually on object storage, where data sits in its original format: JSON logs, CSV extracts, Parquet files. No schema is enforced on write and structure is applied on read, which is why it is called schema-on-read, against the warehouse's schema-on-write. That decouples producer and consumer: the application team drops files and the analytics team decides later what to build. The costs sit elsewhere. With no transactions a reader can see a half-written file. With no catalog nobody knows what is in there, and with no owner anyone dumps anything at any quality until the lake becomes a swamp. The current answer is a table format over the same object storage, adding a catalog and light transactions: the lakehouse layer.

0 تبدیلداده قبل از ذخیره تغییر نمی‌کند؛ ساختار وقت خواندن می‌آیدnothing is transformed before storage; structure arrives at read time
PBمقیاسی که انبار معمولی را از دریاچه جدا می‌کندthe scale that separates a lake from a plain store
1 catalogبدون فهرست، دریاچه فقط یک انبار بی‌برچسب استwithout a catalog a lake is an unlabelled store

تلهٔ رایجThe usual trap

ریختن بدون مالک و فهرست. دریاچه با «بعداً مرتبش می‌کنیم» شروع می‌شود و بعد از یک سال پر از فایل تکراری و بی‌نام است که هیچ‌کس جرئت نمی‌کند پاکشان کند. و گزارش‌ها مستقیم روی همان فایل‌های خام می‌نشینند و عدد اشتباه می‌دهند، چون کسی رکوردهای تکراری را ندیده است.Dumping with no owner and no catalog. The lake begins with “we will tidy it later”, and a year on it is full of duplicated, unnamed files nobody dares delete. And reports sit directly on those raw files and produce wrong numbers, because nobody noticed the duplicate rows.

چرا گزارش ماهانه را روی دیتابیس اپ نمی‌زنیم؟Why not run the monthly report on the app database?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

توی خانه یک دفتر خرج روزانه داری که هر خرید را همان لحظه در آن می‌نویسی. آخر ماه که می‌خواهی بدانی پول کجا رفته، سراغ همان دفتر نمی‌روی؛ عددها را در یک صفحهٔ تازه می‌ریزی: دسته، ماه، جمع. آن صفحه دفتر روزانه نیست و لازم هم نیست باشد؛ انبار داده هم همان صفحهٔ جمع‌بندی است: جای پرسیدن است، نه جای ثبت روز.At home you keep a small notebook where every purchase lands the moment you pay. At the end of the month, to see where the money went, you do not read that notebook; you copy the numbers onto a fresh page — category, month, total. That page is not the daily notebook and does not need to be; a data warehouse is that fresh page, a place to ask questions rather than to record the day.

تشبیه و تصویر ذهنیThe analogy

فروشگاهی را در نظر بگیر که سه جای جدا حساب نگه می‌دارد: صندوق فروش، انبار، و فروش اینترنتی. هر کدام برای کار خودش خوب است؛ صندوق سریع است و انبار دقیق. ولی وقتی مدیر می‌خواهد بداند ماه گذشته کدام جنس سود داشت، این سه هیچ‌کدام جواب را ندارند. برای همین یک اتاق جدا درست می‌کنند: هر شب دادهٔ هر سه را می‌آورند، با یک زبان مشترک می‌نویسند — مثلاً یک محصول، یک کد — و در یک دفتر بزرگ مرتب می‌چینند. بهایش این است که پاسخ‌ها همیشه یک شب عقب‌اند؛ و دقیقاً برای همین است که صندوق را قربانی نمی‌کنند.Picture a shop that keeps three separate sets of books: the till, the stockroom and the online store. Each is good at its own job; the till is fast and the stockroom is precise. But when the manager wants to know which product made money last month, none of the three has the answer. So they set up a separate room: every night the data from all three is brought in, written in one shared language — one product, one code — and laid out in a big, orderly book. The price is that the answers are always a night behind, which is exactly why nobody sacrifices the till for it.

سیستم‌های مبدأSource systemsاپ، صندوق، انبارapp, till, stockاستخراجExtractدسته‌ای، شبانهbatch, nightlyتبدیلTransformیکدست‌سازیcleaningبارگذاریLoadجدول تحلیلیanalytical tablesکوئریQueryتحلیلگرanalyst
داده از چند سیستم بیرون کشیده و تمیز می‌شود و در یک جای جدا و خواندنی می‌نشیند.Data is pulled from many systems, cleaned, and lands in one separate place built for reading.

و بعدش، فنیAnd now, technically

انبار داده یک دیتابیس جداست، معمولاً روی ماشین خودش، که هیچ اپلیکیشنی روی آن تراکنش نمی‌نویسد. داده با یک job دوره‌ای از سیستم‌های مبدأ کشیده می‌شود، تمیز و یکدست می‌شود، و در جدول‌هایی می‌نشیند که برای خواندن طراحی شده‌اند: جدول‌های fact برای رویدادها مثل سفارش و کلیک، و جدول‌های dimension برای توصیف‌ها مثل محصول، مشتری و تاریخ. چیدمان ستونی و denormalize کردن عمدی اینجا عیب نیست، چون کوئری‌ها کم‌تعدادند و هر کدام میلیون‌ها ردیف را می‌خوانند و نوشتن تقریباً وجود ندارد. بارگذاری معمولاً شبانه است، پس انبار همیشه کمی عقب است و همین عقب‌بودن بهای جدا کردنش است. اینکه کوئری تحلیلی روی ماشین جدا می‌نشیند همان چیزی است که تأخیر اپ را نجات می‌دهد: یک گزارش سنگین روی دیتابیس عملیاتی می‌تواند قفل بگیرد و صف بسازد. اما انبار داده خودش یک ادعا دارد: این عددها درست‌اند.A data warehouse is a separate database, usually on its own machine, where no application writes transactions. Data is pulled from source systems by a periodic job, cleaned and made consistent, and lands in tables designed for reading: fact tables for events such as orders and clicks, dimension tables for descriptions such as product, customer and date. Columnar layout and deliberate denormalization are not flaws here, because queries are few and each one reads millions of rows while writes are almost absent. Loading is usually nightly, so the warehouse is always a little behind, and that lag is the price of keeping it separate. Putting the analytical query on its own machine is what saves your application's latency: a heavy report on an operational database can take locks and build a queue. But a warehouse makes a claim of its own: these numbers are right.

1 شبتأخیر معمول بین دادهٔ زنده و انبارa typical lag between live data and the warehouse
N → 1چند سیستم مبدأ، یک مدل مشترکmany source systems, one shared model
read-onlyاپلیکیشن روی انبار تراکنش نمی‌نویسدno application writes transactions to it

همیشه یک شب عقبAlways one night behind

بارگذاری معمولاً دسته‌ای است، پس انبار به‌اندازهٔ یک پنجره عقب است: یک شب، یا اگر حساس باشی پنج دقیقه با بارگذاری افزایشی. کوتاه‌کردن این پنجره گران است، چون هر بار باید تغییرها را از لاگ یا از updated_at بخوانی و همان مسیر را دوباره اجرا کنی. سؤال درست این نیست که «چطور صفرش کنم»، بلکه این است که «کاربر این تأخیر را می‌فهمد یا نه». اگر داشبورد عملیات است و باید همین حالا درست باشد، جایش انبار داده نیست؛ اگر گزارش هفتگی است، یک شب عقب بودن اهمیتی ندارد.Loading is usually batched, so the warehouse trails by one window: a night, or five minutes with incremental loads if you care. Shrinking that window is expensive, because every run has to read the changes from a log or from updated_at and replay the same path. The right question is not “how do I make it zero” but “does the reader understand the delay”. If it is an operations dashboard that must be correct right now, a warehouse is the wrong home for it; if it is a weekly report, a night of lag means nothing.

وقتی دو عدد دو جواب می‌دهندWhen two numbers disagree

انبار داده همیشه یک ادعا دارد: این عدد درست است. ولی درست بودن از مدل می‌آید، نه از جمع‌کردن. اگر دو سیستم مبدأ «مشتری» را دو جور تعریف کنند و تبدیل آن را یکدست نکند، برای یک آدم دو ردیف می‌سازی و گزارش «مشتری فعال» بی‌سر و صدا اشتباه می‌شود. راهش این است که کلید کسب‌وکار را صریح انتخاب کنی، قاعدهٔ یکدست‌سازی را جایی مکتوب نگه داری، و هر بار تعداد ردیف‌ها را با مبدأ مقایسه کنی. بارگذاری هم باید idempotent باشد تا اجرای دوباره دادهٔ تکراری نسازد.A warehouse always makes a claim: this number is right. But rightness comes from the model, not from summing. If two source systems define “customer” differently and the transform does not reconcile them, you build two rows for one person and the active-customer report is quietly wrong. Choose the business key explicitly, keep the reconciliation rule written down somewhere, and compare row counts with the source on every run. Loading also has to be idempotent, so a rerun does not duplicate rows.

تلهٔ رایجThe usual trap

صدا زدن یک replica از دیتابیس عملیاتی با اسم «data warehouse». آن چیز یک کپی است، نه یک مدل تحلیلی؛ کوئری سنگین همان بار و همان قفل‌ها را به سیستم اصلی برمی‌گرداند و تحلیل هم روی داده‌ای انجام می‌شود که برای پرسیدن مرتب نشده است.Calling a read replica of the operational database a data warehouse. It is a copy, not an analytical model: the heavy query puts the same load and the same locks back on production, and the analysis runs over data that was never arranged for questions.

وقتی داده خودش مسئله می‌شود، نه محاسبه.When the data itself is the problem, not the compute.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

قفسهٔ کتاب خانه‌ات با پنجاه جلد را می‌توانی در یک بعدازظهر مرتب کنی: الفبا، موضوع، تمام. همان کار را برای کتابخانهٔ محله با پنجاه هزار جلد در نظر بگیر؛ روش عوض نمی‌شود، ولی یک بعدازظهر جواب نمی‌دهد. اینجا مسئله تندتر خواندن نیست؛ مسئله این است که باید قاعده بسازی، اسم‌های تکراری را یکی کنی و برای جا کم نیاوری — اسم این وضعیت data-intensive است: داده تعیین‌کننده است، نه محاسبه.Your bookcase at home, fifty volumes, you can sort in one afternoon: alphabet, subject, done. Now picture the neighbourhood library with fifty thousand volumes: the method does not change, but one afternoon will not do. The problem is not reading faster; it is that you need a rule, one canonical name per book, and a plan for space — and that situation is what data-intensive means: the data decides, not the computing.

تشبیه و تصویر ذهنیThe analogy

آشپزخانهٔ خانه را در نظر بگیر. شام چهار نفر با هر دستوری جواب می‌دهد؛ فقط باید دستور خوب باشد. شام دویست نفر با همان دستور جواب نمی‌دهد، ولی نه چون آشپز کند است: یخچال جا ندارد، رفت‌وآمد به انبار زیاد می‌شود، و چند نفر باید هم‌زمان از یک در رد شوند. اگر آشپز را دو برابر سریع‌تر کنی، آشپزخانه دو برابر سریع‌تر نمی‌شود؛ فقط زودتر به همان در بسته می‌رسی. سیستم data-intensive هم همین است: به‌جای بهتر کردن محاسبه، باید مسیر جابه‌جایی و نگه‌داری داده را کوتاه کنی، و همین‌جاست که پیچیدگی و هزینه می‌نشیند.Think of your kitchen. Dinner for four works with almost any recipe; the recipe is the only thing that matters. Dinner for two hundred does not work with the same recipe, and not because the cook is slow: the fridge has no room, trips to the pantry multiply, and several people have to pass through one door. Make the cook twice as fast and the kitchen is not twice as fast; you just reach the same closed door sooner. A data-intensive system behaves the same way: instead of improving the computation, you shorten the path the data travels, and that is where the complexity and the cost live.

محاسبه‌محورCompute-intensiveگلوگاه: CPUbottleneck: CPUسریع‌تر: کد بهترfaster: better codeمعیار: ثانیهٔ پردازشmeasure: CPU secondsداده‌محورData-intensiveگلوگاه: جابه‌جایی دادهbottleneck: moving dataسریع‌تر: مسیر کوتاه‌ترfaster: a shorter pathمعیار: تأخیر و توان عبورmeasure: latency, throughput
دو نوع سقف: یکی توان محاسبه، یکی خودِ داده. علاج این دو با هم فرق دارد.Two different ceilings: compute and the data itself. They are fixed in different ways.

و بعدش، فنیAnd now, technically

سیستم data-intensive سیستمی است که در آن حجم داده، پیچیدگی داده یا سرعت تغییرش بیشتر از توان محاسبه تعیین‌کننده است. این سه کلمه مهم‌اند. حجم یعنی چند ترابایت روی دیسک و چند میلیارد ردیف. پیچیدگی یعنی تعداد موجودیت‌ها و ساختارها و مدل‌هایی که باید جواب بدهند. سرعت تغییر یعنی نرخ نوشتن و خواندن، که همان چیزی است که معماری را می‌سازد. در چنین سیستمی کد سریع‌تر نوشتن معمولاً کمکی نمی‌کند؛ چیزی که کمک می‌کند کوتاه‌کردن مسیر داده است: ایندکس، کش، تیکه‌کردن، replica و log. هر کدام از این‌ها یک نسخهٔ دیگر از داده می‌سازد یا یک مرحله را حذف می‌کند، و همین است که طراحی این سیستم‌ها را بیشتر دربارهٔ حرکت داده می‌کند تا دربارهٔ الگوریتم. در مقابل، compute-intensive کاری است که CPU را می‌سوزاند، مثل رمزگذاری یا پردازش تصویر. در عمل سیستمی پیدا نمی‌کنی که فقط یکی باشد؛ آن چیزی که تو را زمین می‌زند معمولاً داده است.A data-intensive system is one where volume, complexity or rate of change of data decides more than raw compute does. All three words matter. Volume means terabytes on disk and billions of rows. Complexity means the number of entities and structures that must answer. Rate of change means how many writes and reads arrive per second, which is what actually shapes the architecture. In such a system, writing faster code usually does not help; shortening the path the data travels does: an index, a cache, a partition, a replica, a log. Each of those either makes another copy of the data or removes a step, which is why designing these systems is mostly about data movement and only partly about algorithms. Compute-intensive work is the opposite kind: encryption, image processing, a simulation. Real systems are never purely one or the other, but the thing that takes you down is almost always the data.

GB → TBفاصله‌ای که یک ماشین را از ظرفیت می‌اندازدthe gap that outgrows one machine
3 محورحجم، پیچیدگی، سرعت تغییر دادهvolume, complexity, rate of change
ms ≠ sفاصلهٔ خواندن یک ردیف تا اسکن تحلیلیa point read versus an analytical scan

چرا سریع‌تر کردن کد جواب نمی‌دهدWhy faster code does not help

اگر نود درصد زمان یک درخواست صرف انتظار برای خواندن یک صفحه از دیسک یا یک رفت‌وبرگشت شبکه شود، دو برابر کردن سرعت کد فقط همان ده درصد باقی‌مانده را نصف می‌کند و زمان کل تقریباً همان می‌ماند. در سیستم data-intensive، بهینه‌سازی واقعی یعنی کم کردن تعداد مسیرها: ایندکسی که اسکن را حذف می‌کند، کشی که رفت‌وبرگشت را حذف می‌کند، یا تیکه‌بندی‌ای که جست‌وجو را به یک ماشین محدود می‌کند. هر کدام از این‌ها یک نسخهٔ اضافی از داده می‌سازد، پس هر بهینه‌سازی داده یک هزینهٔ تازهٔ نگه‌داری هم دارد.If ninety percent of a request's time is spent waiting for a disk page or a network round trip, doubling the speed of the code halves only the remaining ten percent and the total barely moves. In a data-intensive system, real optimization means removing paths: an index that deletes a scan, a cache that deletes a round trip, a partition that confines a lookup to one machine. Each of those makes an extra copy of the data, so every data optimization brings a maintenance bill with it.

تلهٔ رایجThe usual trap

اولین واکنش به کندی، اضافه کردن کش است. کش یک کپی دیگر از داده است؛ اگر مسیر به‌روزرسانی‌اش را نسازی، دادهٔ کهنه را با اطمینان کامل سرو می‌کنی. اگر گلوگاه نوشتن است، کش فقط آن را پنهان می‌کند و مشکل را به فردا موکول می‌کند.The first reaction to slowness is to add a cache. A cache is another copy of the data; without a path that keeps it current you serve stale rows with complete confidence. And when the bottleneck is writes, a cache only hides it and moves the problem to tomorrow.

این داده را از نو بسازی، همان درمی‌آید؟If you rebuilt this from scratch, would it come out the same?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

آخر بعضی دفترچه‌های تلفن قدیمی یک فهرست الفبایی از اسم‌ها بود. کسی آن را جدا نوشته بود تا پیدا کردن اسم چند ثانیه‌ای شود. اگر دفترچه را از نو بنویسی، آن فهرست هم از نو ساخته می‌شود؛ خودش هیچ اطلاعات تازه‌ای ندارد، فقط رسیدن به اطلاعات را آسان می‌کند — اسم این جور داده‌ها دادهٔ مشتق است: چیزی که وجودش را از دادهٔ دیگری می‌گیرد.Some old phone books ended with an alphabetical index of names. Someone wrote it out separately so finding a name takes seconds. Rewrite the book and the index is rebuilt; it adds no information of its own, it only makes the information easier to reach — that is derived data: it borrows its existence from something else.

تشبیه و تصویر ذهنیThe analogy

در دفتر مشق مدرسه، آخر جلد یک جدول ضرب چاپی بود. کسی آن را از روی همان ضرب‌ها نوشته بود، و اگر گم می‌شد دوباره از نو نوشته می‌شد. سودش این بود که سر امتحان لازم نبود حساب کنی؛ نگاه می‌کردی و جواب را برمی‌داشتی. ضررش هم این بود که اگر جدول یک جا غلط چاپ می‌شد، تو هم غلط جواب می‌دادی و خبر نداشتی. هر ایندکس، هر کش و هر جدول جمع‌بندی در سیستم تو یکی از همان جدول‌های ضرب است: تا وقتی از منبعش تغذیه می‌شود سریع است، و همان لحظه که جدا بیفتد، با اعتماد کامل دروغ می‌گوید.At the back of a school notebook there was a printed multiplication table. Someone had written it out from the same facts, and if it was lost it would simply be written again. The gain was that in an exam you did not have to multiply; you looked and took the answer. The cost was that a misprint made you wrong without telling you. Every index, cache and summary table in your system is one of those tables: fast while it is fed from its source, and confidently wrong the moment it drifts away.

منبع حقیقتSystem of recordایندکس جست‌وجوSearch indexکش و viewCache and viewجدول جمع‌بندیSummary tableهمه از یک منبع ساخته می‌شوند و همه دوباره ساختنی‌اندAll built from one source, and all rebuildable
دادهٔ اصلی یکی است؛ بقیه از آن ساخته می‌شوند و اگر پاک شوند، از نو ساخته می‌شوند.One source of truth; the rest is built from it and can be rebuilt if lost.

و بعدش، فنیAnd now, technically

هر چیزی که از دادهٔ اصلی ساخته می‌شود و می‌توان از نو ساختش، دادهٔ مشتق (derived data) است: ایندکس ثانویه، کش، view مادی‌شده، ایندکس جست‌وجوی متن کامل، جدول جمع‌بندی روزانه، یا یک کپی denormalize‌شده برای خواندن سریع. ارزشش در مسیر خواندن است: به‌جای گشتن در منبع، از یک ساختار آماده جواب می‌گیری. هزینه‌اش در مسیر نوشتن است: هر نوشتن باید چند نسخهٔ مشتق را هم تازه کند، و همان‌جا دو نوشتن مستقل شروع می‌شود که یکی‌شان می‌تواند انجام شود و دیگری نه. دو راه نگه‌داری داری: بازسازی کامل که ساده است و کند، یا به‌روزرسانی افزایشی که سریع است و مستعد جدا افتادن. آزمایش واقعی این است که بتوانی مشتق را در محیطی جدا از منبع بسازی و با نسخهٔ زنده مقایسه کنی؛ اگر نمی‌توانی، آن چیز مشتق نیست، منبع دوم است. همین آزمایش است که مرز بین یک بهینه‌سازی و یک باگ آینده را می‌کشد.Anything built from primary data that could be rebuilt is derived data: a secondary index, a cache, a materialized view, a full-text index, a daily summary table, a denormalized copy for fast reads. Its value sits in the read path: instead of searching the source you answer from a prepared structure. Its cost sits in the write path: every write must refresh several derived copies, and that is exactly where two independent writes appear, one of which can happen while the other does not. There are two ways to maintain it: a full rebuild, simple and slow, or incremental updates, fast and prone to drift. The real test is whether you can build the derived copy somewhere else, from the source, and diff it against the live one; if you cannot, it is not derived data, it is a second source of truth. That test is the line between an optimization and a future bug.

N کپیهر نوشتن باید N نسخهٔ مشتق را هم تازه کندone write must refresh N derived copies
2 راهبازسازی کامل، یا به‌روزرسانی افزایشیfull rebuild, or incremental update
1 منبعدادهٔ مشتق همیشه از یک منبع ساخته می‌شودderived data is always built from one source

بازسازی، تنها آزمایش واقعیA rebuild is the only real test

هر ادعایی که «این داده مشتق است» باید با یک کار ساده سنجیده شود: یک کپی از منبع بردار، مشتق را از صفر روی آن بساز، و خروجی را با نسخهٔ زنده مقایسه کن. اگر تعداد ردیف‌ها یکی بود و محتوا هم یکی بود، مشتق سالم است. اگر نشد، دو حالت داری: یا ساخت از منبع ممکن نیست، که یعنی منبع دومی داری و باید تصمیم بگیری کدام مرجع است، یا ممکن است ولی کسی تا حالا امتحانش نکرده، که یعنی تا روز خرابی نمی‌دانی کدام کپی درست است. این آزمایش را باید بتوانی در یک محیط جدا اجرا کنی، بدون دست زدن به نسخهٔ زنده.Any claim that “this data is derived” should survive one simple exercise: take a copy of the source, build the derived copy from scratch on top of it, and compare that with the live one. If the row counts match and the contents match, the derived copy is healthy. If not, there are two cases: either rebuilding from the source is impossible, which means you have a second source and must decide which one is authoritative, or it is possible but nobody ever tried, which means you will not know which copy is right until the day it breaks. And the exercise has to run somewhere separate, without touching the live copy.

هزینه روی نوشتن می‌نشیندThe bill lands on writes

در مسیر خواندن، دادهٔ مشتق تقریباً مجانی است؛ همان چیزی است که برایش ساخته‌ای. هزینه‌اش جای دیگری است: هر نوشتن باید چند ساختار را با هم تازه کند و این ساختارها در چند سیستم مختلف‌اند. اگر نوشتن در دیتابیس موفق شود و فرستادن پیام به سیستم ایندکس شکست بخورد، یک نسخه تازه و یک نسخهٔ کهنه داری و هیچ‌کس نمی‌فهمد. این همان جایی است که میان «همه را با هم بنویس» و «یک منبع، بقیه دنبالش» باید انتخاب کنی. راه دوم همیشه کمی عقب است، ولی تنها راهی است که می‌شود دلیل درستی‌اش را نشان داد.On the read path, derived data is almost free; that is what it was built for. The cost is elsewhere: every write has to refresh several structures, and those structures live in several different systems. If the database write succeeds and publishing to the index fails, you have one fresh copy, one stale copy, and nobody who notices. That is where you choose between writing everything together and keeping one source that the rest follows. The second option is always a little behind, and it is the only one whose correctness you can actually argue for.

تلهٔ رایجThe usual trap

نوشتن در دو جا. کد اپ ردیف را در دیتابیس می‌نویسد و بعد، در خط بعدی، ایندکس جست‌وجو را صدا می‌زند؛ اگر بین این دو خط پروسه بیفتد، ایندکس چیزی را نشان می‌دهد که وجود ندارد. هر جا دو نوشتن داری، یک لحظه هست که یکی انجام شده و دیگری نه؛ راهش یکی کردن مسیر نوشتن است، نه دقت بیشتر.Writing twice. The application writes the row to the database and then, on the next line, calls the search index; if the process dies between those two lines, the index shows something that does not exist. Wherever there are two writes there is a moment when one happened and the other did not, and the answer is one write path, not more care.

اگر بین دو نوشتن پروسه بمیرد، کدام یکی انجام شده؟If the process dies between two writes, which one happened?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

قبض گاز را که پرداخت می‌کنی، هم در دفترچهٔ آشپزخانه می‌نویسی و هم در دفترچهٔ کیف. یک بار تلفن زنگ می‌زند و یکی از دو دفتر نانوشته می‌ماند. ماه بعد یکی می‌گوید «پرداخت شده» و دیگری می‌گوید «بدهی». نوشتن دوگانه همین است: دو جا نوشتن، بدون اینکه یک کار باشد.When you pay the gas bill you write it in the kitchen notebook and in the one in your bag. Once the phone rings mid-way and one of the two stays unwritten. Next month one says paid and the other says owed. Dual write is the same: two places written, and no single act.

تشبیه و تصویر ذهنیThe analogy

دو دفتر داشتن در نظر اول ایرادی ندارد؛ اشکال وقتی پیدا می‌شود که بخواهی مطمئن باشی هر دو با هم نوشته شده‌اند. هیچ راهی نیست که دو حرکت جدا را با هم انجام دهی، و همیشه لحظه‌ای هست که یکی انجام شده و دیگری نه. می‌توانی دوباره تلاش کنی، ولی تلاش دوباره برای دومی یعنی ممکن است دو بار نوشته شود یا دیرتر از نوشتهٔ بعدی برسد. می‌توانی هر دو را به یک قفل ببندی و منتظر بمانی، ولی قفل روی دو سیستم یعنی یکی کند و بی‌اعتنا به دیگری، و یک قطعی شبکه کار هر دو را متوقف می‌کند.Two notebooks look harmless at first; the trouble starts when you want to be sure both were written together. There is no way to perform two separate acts at once, and there is always a moment when one happened and the other did not. You can retry, but a retry of the second means it may be written twice or land later than the next note. You can lock both together and wait, but a lock across two systems means one is slow and ignores the other, and a single network cut stops both.

نوشتن دوگانهDual writeدو تراکنش جداtwo separate commitsبین‌شان پنجرهٔ خرابیa failure window betweenترتیب معلوم نیستorder unknownیک نوشتن، بعد لاگOne write, then logهمه در یک تراکنشeverything in one commitرله از لاگ می‌خواندa relay reads the logترتیب حفظ می‌شودorder preserved
دو نوشتن مستقل هرگز با هم موفق نمی‌شوند؛ یک نوشتن و یک لاگ، ترتیب و تکرار را از یک جا می‌آورند.Two independent writes never succeed together; one write plus one log gives order and retries a single source.

و بعدش، فنیAnd now, technically

نوشتن دوگانه یعنی اپ یک تغییر را در دیتابیس می‌نویسد و در همان مسیر کد به یک سیستم دوم هم می‌فرستد: ایندکس جست‌وجو، کش، صف پیام. این دو عمل دو تراکنش جدا هستند و هیچ مرزی نیست که هر دو را با هم موفق یا با هم ناموفق کند. پنجرهٔ خرابی کوچک نیست: پروسه می‌تواند بعد از نوشتن اول بمیرد، شبکه جواب دوم را گم کند در حالی که نوشتن انجام شده، یا تایم‌اوت درست همان‌جا رخ دهد. نتیجه سه حالت است: نوشته شده و منتشر نشده، منتشر شده و نوشته نشده، یا هر دو با تأخیری که ترتیب را به هم می‌زند. راه درست این است که یک نوشتن داشته باشی و نسخهٔ دوم از آن مشتق شود: نوشتن در همان تراکنش داخل جدول outbox و یک رله که آن را منتشر می‌کند، یا خواندن لاگ تغییرات با CDC. آن‌وقت ترتیب و تکرار و بازیابی همه از یک جا می‌آیند. کامیت دوفازی هم هست، ولی کند و شکننده است و اگر یک سیستم در دسترس نباشد کل کار را می‌خواباند.Dual write means the application writes a change to the database and then, in the same code path, sends it to a second system: a search index, a cache, a message queue. Those are two separate transactions, and no boundary makes them both succeed or both fail. The failure window is not small: the process can die after the first write, the network can lose the second reply while the write happened, or a timeout can land exactly there. Three outcomes follow: written but not published, published but not written, or both with a delay that reorders them. The right shape is one write and a derived second copy: write into an outbox table inside the same transaction and let a relay publish it, or read the change log with CDC. Then order, retries and recovery all come from one place. Two-phase commit is an option, but it is slow and fragile, and one unavailable system stalls everything.

2 نوشتندو عمل جدا که هیچ ضمانتی با هم ندارندtwo separate acts with no shared guarantee
1 پنجرهبین دو نوشتن همیشه لحظه‌ای هست که یکی انجام شدهbetween them there is always a moment when only one happened
at-least-onceتلاش دوباره، پیام تکراری می‌سازد نه درستa retry produces duplicates, not correctness

تلهٔ رایجThe usual trap

پوشاندن مسئله با try/catch و retry. تلاش دوباره پیام تکراری می‌سازد، و اگر تأخیر داشته باشد پیام کهنه روی دادهٔ تازه می‌نشیند. یا نوشتن دوم را fire-and-forget می‌کنی و با مرگ پروسه رویداد برای همیشه گم می‌شود و هیچ‌کس هم خبردار نمی‌شود.Papering over it with try/catch and a retry. The retry produces duplicates, and a delayed retry lands a stale message on top of fresh data. Or you make the second write fire-and-forget, the process dies, and the event is gone for good with nobody the wiser.

ETL

استخراج، تبدیل، بارگذاری فصل ۱Chapter 1 · دیدن در متنsee in context

داده را قبل از آوردن تمیز کنیم یا بعدش؟Clean the data before it lands, or after?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

قبل از اسباب‌کشی، هر کشو را خالی می‌کنی، چیزهای تکراری و شکسته را کنار می‌گذاری، و بعد در خانهٔ جدید هر چیز سر جای مشخصش می‌رود. اگر همه را همان‌طور که هست در اتاق جدید بریزی، تا سال بعد نمی‌دانی کدام کارتون کجاست. ETL همین ترتیب است: اول مرتب کن، بعد بچین.Before moving house you empty every drawer, set aside the duplicates and the broken things, and then give each thing a place in the new home. Pour it all into the new room as it is and you will not know which box is which for a year. ETL is that same order of work: sort first, place second.

تشبیه و تصویر ذهنیThe analogy

شرکتی را در نظر بگیر که سه دفتر دارد: فروش، انبار، پشتیبانی. هر کدام فایل خودش را دارد و هر کدام «مشتری» را جور دیگری می‌نویسد؛ یکی با کد ملی، یکی با شمارهٔ تلفن، یکی با ایمیل. برای ساختن یک گزارش واحد، اول هر سه را می‌خوانی، بعد باید بفهمی کدام ردیف همان آدم است و اسم‌ها را یکدست کنی، و آخر در یک جدول تمیز بنویسی. بهایش این است که تبدیل، جایی است که تصمیم‌های انسانی می‌نشیند: اگر قاعدهٔ یکدست‌سازی اشتباه باشد، همهٔ گزارش‌های بعدی همان اشتباه را با اطمینان کامل تکرار می‌کنند و کسی هم داد نمی‌زند.Picture a company with three offices: sales, stock and support. Each keeps its own file and each writes “customer” differently — one by national ID, one by phone number, one by email. To build one report you first read all three, then decide which rows are the same person and reconcile the names, and only then write them into one clean table. The price is that the transform is where human judgement sits: if the reconciliation rule is wrong, every later report repeats that mistake with complete confidence, and nothing complains.

مبدأهاSourcesاپ و صندوقapp and tillاستخراجExtractدسته‌ایbatchتبدیلTransformیکدست‌سازیcleaningبارگذاریLoadکلید کسب‌وکارbusiness keyانبار دادهWarehouseآمادهٔ پرسشready to query
مسیر سه‌مرحله‌ای: اول کشیدن، بعد یکدست کردن، آخر نشستن در انبار.Three stages: pull it out, make it consistent, land it in the warehouse.

و بعدش، فنیAnd now, technically

ETL سه مرحله دارد که هر کدام می‌تواند جدا شکست بخورد. Extract با کوئری دوره‌ای، با dump یا با خواندن لاگ انجام می‌شود و باید بداند از کجا ادامه دهد؛ همان نشانک است که تعیین می‌کند job بعدی از کدام ردیف شروع کند. Transform جایی است که تصمیم‌های انسانی می‌نشیند: یکسان‌کردن قالب تاریخ، تبدیل ارز، یکی کردن دو رکورد که یک آدم‌اند، و ساختن کلیدهای dimension. Load یا کل جدول را از نو می‌سازد یا افزایشی merge می‌کند روی کلید کسب‌وکار. کلید موفقیت، idempotent بودن است: اجرای دوبارهٔ همان بازه باید همان نتیجه را بدهد، وگرنه یک خرابی و یک اجرای مجدد دو برابر داده می‌سازد. در نسخهٔ ELT دادهٔ خام اول در انبار می‌نشیند و تبدیل با توان خود انبار انجام می‌شود؛ مزیتش این است که خام را نگه می‌داری و بعداً می‌توانی جور دیگری تبدیل کنی.ETL has three stages, and each can fail on its own. Extract runs as a periodic query, a dump or a log read, and it must know where to resume; that bookmark decides which row the next run starts from. Transform is where human judgement sits: normalising date formats, converting currencies, merging two records that are one person, and building dimension keys. Load either rebuilds the whole table or merges incrementally on the business key. The key to it working is idempotency: rerunning the same window must produce the same result, or one failure plus one rerun leaves you with double the data. In the ELT variant the raw data lands first and the warehouse's own compute does the transform, which keeps the raw layer around so you can transform it differently later.

1 بار در شبدورهٔ معمول اجرای job دسته‌ایa typical cadence for the batch job
3 مرحلهاستخراج، تبدیل، بارگذاری؛ هر کدام جدا می‌شکندextract, transform, load; each fails on its own
idempotentاجرای دوبارهٔ job نباید ردیف تکراری بسازدa rerun must not duplicate rows

ETL یا ELTETL or ELT

فرق در ترتیب است، ولی نتیجه فرق می‌کند. در ETL داده پیش از نشستن در انبار تمیز می‌شود، پس انبار فقط نسخهٔ تمیز را می‌بیند و دادهٔ خام جایی نگه داشته نمی‌شود. در ELT اول خام را می‌ریزی و بعد با موتور انبار تبدیل می‌کنی، که یعنی هر وقت بفهمی قاعدهٔ تبدیل اشتباه بوده، می‌توانی از خام دوباره بسازی. اگر دادهٔ شخصی و حساس داری و قانون می‌گوید نباید نگه داشته شود، ETL ساده‌تر است؛ اگر می‌خواهی تاریخ را دست‌نخورده داشته باشی و بعداً سؤال تازه‌ای بپرسی، ELT جواب می‌دهد. هیچ‌کدام مطلقاً بهتر نیست؛ بستگی دارد به این‌که چه چیزی را نمی‌توانی دور بریزی.The difference is order, but the result differs. In ETL the data is cleaned before it lands, so the warehouse only ever sees the clean version and the raw copy is not kept. In ELT the raw data lands first and the warehouse engine does the transform, which means that when you discover the rule was wrong you can rebuild from raw. If you hold sensitive personal data and a rule says it must not be kept, ETL is simpler; if you want the history untouched so you can ask a new question later, ELT pays off. Neither is absolutely better; it depends on what you are not allowed to throw away.

بارگذاری نصفه، بدترین حالتA half-finished load is the worst case

job که وسطش می‌میرد از هر شکست دیگری بدتر است، چون دادهٔ ناقص می‌نشیند و هیچ خطایی هم بعدش بالا نمی‌آید. نصف ردیف‌های یک شب بارگذاری شده و گزارش صبح کاملاً باورپذیر به نظر می‌رسد. راهش این است که هر بار یا کل بازه یک‌جا ثبت شود، یا هر ردیف با نشانهٔ batch بیاید تا بدانی کدام batch کامل است. یک جدول کنترل کوچک که وضعیت هر اجرا را نگه می‌دارد از هر ابزار مانیتورینگی ارزان‌تر است، و همان چیزی است که شب بعد نجاتت می‌دهد.A job that dies halfway is worse than any other failure, because partial data lands and nothing raises an error afterwards. Half of one night's rows are loaded and the morning report looks entirely believable. The answer is to make each window commit as a unit, or to tag every row with its batch so you can tell which batch is complete. A small control table that records the state of each run is cheaper than any monitoring tool, and it is the thing that saves you the next night.

تلهٔ رایجThe usual trap

job را بدون idempotent نوشتن و بعد با خیال راحت دوباره اجرا کردن. هر بار که یک شب خراب می‌شود و دوباره می‌زنی، ردیف‌ها دو برابر می‌شوند و کسی هم متوجه نمی‌شود، چون نمودارها فقط بالا می‌روند. کلید یکتا روی کلید کسب‌وکار و بازه بگذار و بنویس که اجرای دوباره باید بی‌اثر باشد.Writing the job without idempotency and then rerunning it freely. Every failed night you retry doubles the rows, and nobody notices because the charts only go up. Put a unique key on the business key plus the window, and write down that a rerun must be a no-op.

یک سیستم برای فروش امروز و گزارش پارسال؟One system for today's sales and last year's report?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

میز ناهارخوری خانه هم جای غذا خوردن است و هم جای اتو کردن. هر بار که می‌خواهی اتو کنی باید شام را جمع کنی و هر بار که مهمان می‌آید باید تخته را برداری. یک میز بزرگ‌تر هر دو کار را می‌دهد، ولی تا وقتی هر دو همزمان رویش انجام شوند، یکی مزاحم دیگری است. پردازش ترکیبی همین معامله است: یک میز، دو کار، و دعوای همیشگی سر جای هم.The dining table at home is where you eat and where you iron. Every time you want to iron you have to clear dinner away, and every time guests come you have to move the board. One bigger table does both jobs, but as long as both happen on it at once, one is in the other's way. HTAP is that bargain: one table, two jobs, and a permanent argument about space.

تشبیه و تصویر ذهنیThe analogy

فرق این میز با خرید دو میز کوچک را حساب کن. دو میز یعنی هر کار سر جای خودش، ولی دو برابر جا و هزینه. یک میز یعنی نصف جا و یک بار خریدن، ولی یک لحظهٔ شلوغی روی هر دو اثر می‌گذارد. حالا همان میز را بزرگ کن تا اتاق کار هم رویش جا شود: اتوی نیمه‌کاره و ظرف‌های نشسته و لپ‌تاپ باز همه با هم روی یک سطح‌اند. در یک دیتابیس این شلوغی به شکل مصرف CPU و حافظه و قفل روی صفحه‌ها ظاهر می‌شود، و بدترین حالتش این است که یک گزارش سنگین تراکنش یک مشتری را چند ثانیه معطل کند.Work out the difference from buying two small tables. Two tables means each job in its own place, at twice the room and cost. One table means half the room and one purchase, but any crowded moment touches both jobs. Now widen that table until the desk fits too: the half-finished ironing, the unwashed dishes and the open laptop share one surface. In a database that crowding shows up as CPU, memory and page locks — and the worst version is one heavy report stalling a customer's transaction for seconds.

دو سیستم جداTwo systemsکپی با ETLa copy via ETLتأخیر مستقلits own lagمنابع کاملاً جداfully separate resourcesیک موتور HTAPOne HTAP engineدو مسیر روی یک دادهtwo paths on one data setبدون کپی و ETLno copy, no ETLرقابت بر سر منابعcompeting for resources
دو سیستم، دو کپی و یک ETL در برابر یک موتور با دو مسیر؛ سود در حذف کپی است، هزینه در رقابت بر منابع.Two systems with a copy and an ETL versus one engine with two paths; the gain is the copy, the cost is contention.

و بعدش، فنیAnd now, technically

HTAP یعنی یک موتور هم تراکنش‌های کوتاه را جواب بدهد و هم اسکن‌های بلند تحلیلی، بدون کپی جدا با ETL. اجرای رایج امروزش این است که موتور یک نسخهٔ ستونی از همان داده را، معمولاً در حافظه، کنار نسخهٔ ردیفی نگه می‌دارد و پرس‌وجوها را بر اساس هزینه به یکی از دو مسیر می‌فرستد؛ خواندن تحلیلی روی یک snapshot سازگار انجام می‌شود تا نویسنده‌ها را قفل نکند. این طرح سه هزینه دارد. هر نوشتن باید در هر دو قالب نگه داشته شود، پس نوشتن گران‌تر و حافظه بیشتر می‌شود. یک اسکن بلند هنوز پهنای باند حافظه و CPU مشترک را می‌خورد، و هیچ governor‌ای جای جدایی فیزیکی را نمی‌گیرد. و یک سیستم یک دامنهٔ خرابی است: باگ یا ارتقا یا از کار افتادنش هر دو کار را با هم می‌خواباند.HTAP means one engine answers both short transactions and long analytical scans without a separate copy built through ETL. The common implementation keeps a columnar version of the same data, usually in memory, beside the row store, and routes each query to one of the two paths by cost; the analytical read runs on a consistent snapshot so it does not lock writers. That design has three costs. Every write must be maintained in both formats, which makes writes more expensive and needs more memory. A long scan still consumes shared memory bandwidth and CPU, and no resource governor replaces physical separation. And one system is one failure domain: a bug, an upgrade, or an outage takes both workloads down together.

2 کارتراکنش کوتاه و اسکن بلند، روی یک موتورshort transactions and long scans on one engine
2× نوشتنهر تغییر هم در قالب ردیفی و هم ستونی نگه داشته می‌شودevery change is kept in both row and column form
1 نسخهبرخلاف انبار داده، کپی جدا و تأخیر ETL نداردunlike a warehouse, no separate copy and no ETL lag

تلهٔ رایجThe usual trap

حذف جدایی به امید HTAP. تیم گزارش را روی سیستم تولیدی می‌گذارد و ماه بعد می‌بیند ساعت پایان ماه صفحهٔ پرداخت کند شده؛ چون کپی ستونی و governor فقط شدت رقابت را کم می‌کنند، حذفش نمی‌کنند. و اگر کپی ستونی async تازه شود، گزارش می‌تواند ترکیبی از دو لحظه ببیند.Removing the separation on the promise of HTAP. The reporting team moves onto the production system, and a month later checkout is slow at month end, because a columnar copy and a governor only soften contention, they do not remove it. And if the columnar copy refreshes asynchronously, a report can mix two moments.

یک سیستم، هزار مشتری، و هیچ‌کدام نباید دیگری را ببیند.One system, a thousand customers, and none may see another.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

ماشین لباسشویی مشترک ساختمان. هر واحد نوبت خودش را دارد و لباس خودش را می‌آورد، ولی ماشین یکی است. روزی که همسایهٔ طبقهٔ سوم لحاف بزرگش را بیندازد نوبت تو دیر می‌شود، و روزی که یک جفت جوراب قرمز جا بماند لباس سفید همه صورتی می‌شود. چندمستأجری همین است: یک سیستم مشترک، با مرزی که نگذارد جوراب کسی به لباس دیگری برسد.The shared washing machine in the building. Each flat has its own turn and brings its own clothes, but there is one machine. The day the neighbour from the third floor puts in a huge quilt, your turn runs late; the day one red sock is left behind, everyone's whites come out pink. Multitenancy is that: one shared system, with a boundary that stops one person's sock reaching another's washing.

تشبیه و تصویر ذهنیThe analogy

سه راه داری، و هر سه در همین ساختمان معنا دارند. اول ماشین مشترک با نوبت‌بندی: ارزان و برای همه، به شرطی که کسی نوبت دیگری را ندزدد. دوم اینکه هر واحد ماشین خودش را داشته باشد: دیگر جوراب قرمز کسی به لباس تو نمی‌رسد، ولی ده ماشین داری که هر کدام خراب شود کسی نیست درستش کند. سوم اینکه هر واحد ساختمان خودش را داشته باشد: بهترین جدایی، بیشترین هزینه. هر قدم به سمت جدایی، امنیت بیشتر و پول و سادگی کمتر.You have three options, and all of them make sense in this building. First, the shared machine on a rota: cheap and available to all, as long as nobody steals another's turn. Second, each flat gets its own machine: nobody's red sock reaches your whites now, but you own ten machines and nobody to fix the broken one. Third, each flat gets its own building: the best isolation, the highest cost. Every step towards separation buys security and gives up money and simplicity.

یک جدول مشترک با ستون مستأجرOne table, a tenant columnschema جدا برای هر مستأجرOne schema per tenantدیتابیس جدا برای هر مستأجرOne database per tenantسرور جدا برای هر مستأجرOne server per tenant
چهار پلهٔ جدایی، از اشتراکی به جدا؛ هر پله امنیت بیشتری می‌دهد و کار و هزینهٔ بیشتری می‌خواهد.Four rungs from shared to separate; each buys more isolation and demands more work and money.

و بعدش، فنیAnd now, technically

چندمستأجری یعنی یک نصب نرم‌افزاری به چند مشتری جدا سرویس بدهد، و سؤال اصلی یک کلمه است: مرز کجاست. چهار مدل رایج، از اشتراکی به جدا، این‌طور مرتب می‌شوند: یک schema مشترک با ستون tenant_id؛ schema جدا برای هر مستأجر؛ دیتابیس جدا برای هر مستأجر؛ و سرور جدا برای هر کدام. هر قدم به سمت جدا شدن، جدایی داده و دامنهٔ خرابی را بهتر می‌کند و هزینه و کار عملیاتی را بالا می‌برد؛ هزار دیتابیس یعنی هزار مهاجرت schema و هزار نسخهٔ پشتیبان. در مدل اشتراکی دو خطر جدی داری: نشت داده با یک کوئری که فیلتر مستأجر را جا انداخته، و همسایهٔ پرسروصدا که با یک اسکن بافر و CPU و IOPS مشترک را می‌خورد. جواب هر دو ساختاری است: row-level security تا فیلتر از دست کد نرود، و سهمیه و صف منصفانه برای هر مستأجر. کلید کش و کلید صف هم باید مستأجر را در خودشان داشته باشند، وگرنه داده از راه کش بیرون می‌زند.Multitenancy means one software installation serves several separate customers, and the main question is one word: where is the boundary. Four common models run from shared to separate: one schema with a tenant_id column; a schema per tenant; a database per tenant; a server per tenant. Each step towards separation improves data isolation and shrinks the blast radius, and raises cost and operational work — a thousand databases means a thousand migrations and a thousand backups. The shared model carries two serious risks: a leak from one query that forgot the tenant filter, and a noisy neighbour whose scan eats the shared buffer pool, CPU and IOPS. Both answers are structural: row-level security so the filter cannot be forgotten, and per-tenant quotas and fair queueing. Cache and queue keys must carry the tenant too, or data escapes through the cache.

1 schemaساده‌ترین مدل: همه در یک schema با ستون tenant_idthe simplest model: one schema with a tenant_id column
1 کوئرییک کوئری بدون فیلتر مستأجر، یعنی نشت دادهone unfiltered query is a data leak
N مستأجربا رشد N، جداسازی قوی‌تر گران‌تر می‌شودas N grows, stronger isolation costs more

تلهٔ رایجThe usual trap

تکیه بر این‌که هر کوئری یک فیلتر مستأجر دارد. یک گزارش، یک کلید کش، یا یک job شبانه که فیلتر را جا می‌گذارد کافی است تا دادهٔ یک مشتری سر از خروجی مشتری دیگر دربیاورد، و این تنها اشتباهی است که با عذرخواهی درست نمی‌شود.Trusting every query to carry a tenant filter. One report, one cache key, or one nightly job that forgets it is enough for one customer's data to surface in another's output, and that is the one mistake an apology cannot fix.

جواب یک سؤال، از میان میلیون ردیف.One answer, pulled out of a million rows.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

آخر ماه می‌خواهی بدانی چقدر خرج کرده‌ای. سراغ تک‌تک رسیدها نمی‌روی تا «این خرید چقدر بود» را ببینی؛ همهٔ رسیدهای ماه را جلوی خودت می‌ریزی، دسته‌بندی می‌کنی، و یک جمع می‌گیری. پردازش تحلیلی همین جمع‌زدن روی انبوه است، نه پیدا کردن یک رسید.At the end of the month you want to know what you spent. You do not pull out receipts one by one to check what this purchase cost; you spread the whole month's receipts in front of you, sort them into categories, and take one total. That is OLAP: summing over a pile, not fetching one slip.

تشبیه و تصویر ذهنیThe analogy

انبار بزرگی را تصور کن. کارگر انبار روزی چند بسته برمی‌دارد و هر بسته را از قفسهٔ مشخصی می‌گیرد؛ سرعتش به این بستگی دارد که قفسه را زود پیدا کند. مدیر فروش همان انبار را جور دیگری نگاه می‌کند: می‌خواهد بداند تابستان گذشته کدام سه قلم بیشتر فروش رفت. او قفسه‌ها را یکی‌یکی نمی‌گردد؛ همهٔ برگه‌های فروش را روی هم می‌ریزد و جمع می‌زند. کار اول به ازای هر بسته معنا دارد، دومی به ازای همهٔ برگه‌ها؛ و بدترین کار این است که بخواهی دومی را روی همان قفسهٔ اولی انجام دهی.Picture a large stockroom. A picker takes out a few parcels a day, each from a known shelf, and his speed depends on finding that shelf quickly. The sales manager looks at the same stockroom differently: he wants to know which three products sold best last summer. He does not walk the shelves; he piles up every sales slip and adds them. The first job makes sense per parcel, the second per pile — and the worst mistake is trying to do the second on the first one's shelves.

سؤال تحلیلیAnalytical questionیک عدد می‌خواهیyou want one numberاسکن ستون‌هاColumn scanمیلیون‌ها ردیفmillions of rowsگروه‌بندی و جمعGroup and sumروی همان مسیرas it streamsجواب کوچکSmall resultچند ردیفa few rows
ورودی بزرگ، خروجی کوچک؛ هزینه در خواندن است، نه در نوشتن.A big input, a small output; the cost is in reading, never in writing.

و بعدش، فنیAnd now, technically

OLAP یعنی کوئری‌هایی که کسر بزرگی از داده را می‌خوانند و خروجی کوچکی می‌دهند: گروه‌بندی روی میلیون‌ها ردیف، اتصال جدول‌های fact و dimension، یا یک تابع پنجره‌ای روی کل تاریخ. چون ورودی بزرگ است و خروجی کوچک، هزینه در اسکن است نه در محاسبه. برای همین ذخیره‌سازی ستونی جواب می‌دهد: اگر از دویست ستون فقط سه تا را می‌خواهی، چیدمان ردیفی همهٔ دویست ستون را می‌خواند و چیدمان ستونی فقط همان سه تا را، و چون مقدارهای یک ستون از یک جنس‌اند خوب فشرده می‌شوند. این بار معمولاً تعداد کمی کاربر هم‌زمان دارد، تأخیر ثانیه تا دقیقه را تحمل می‌کند، و نوشتنش دسته‌ای است نه ردیفی. جداکردنش از OLTP هم به همین دلیل است: یک اسکن بیست دقیقه‌ای نباید قفل تراکنش‌های مشتری را بگیرد.OLAP means queries that read a large fraction of the data and return a small result: grouping over millions of rows, joining fact and dimension tables, or a window function across all history. Because the input is large and the output small, the cost is in scanning, not in computing. That is why columnar storage wins: if you want three columns out of two hundred, a row layout reads all two hundred and a column layout reads only the three, and values of one type compress well together. This load usually has few concurrent users, tolerates seconds to minutes of latency, and writes in bulk rather than row by row. Keeping it off OLTP is for the same reason: a twenty-minute scan must not take locks on customer transactions.

GB → KBاز اسکن گیگابایت تا جواب چند کیلوبایتیscan gigabytes, return kilobytes
2–3 ستوناز میان صدها ستون، همین چند تا خوانده می‌شودa few columns read out of hundreds
s → minتأخیر قابل قبول یک کوئری تحلیلیtolerable latency for an analytics query

چرا ستونی ذخیره می‌کنندWhy they store columns

در چیدمان ردیفی، ردیف‌های یک جدول پشت سر هم روی صفحه می‌نشینند، پس خواندن سه ستون از دویست ستون یعنی خواندن کل ردیف‌ها و دور ریختن بقیه. در چیدمان ستونی، مقدارهای هر ستون پشت سر هم می‌آیند: فقط ستون‌های لازم خوانده می‌شوند، و چون همه از یک جنس‌اند فشرده‌سازی هم چند برابر بهتر جواب می‌دهد. بهایش این است که نوشتن یک ردیف کامل گران می‌شود و به‌روزرسانی درجا سخت است. به همین دلیل این سیستم‌ها دسته‌ای بارگذاری می‌شوند، نه ردیف‌به‌ردیف.In a row layout the rows of a table sit next to each other, so reading three columns out of two hundred means reading whole rows and discarding most of them. In a column layout the values of each column sit together: only the needed columns are read, and because they share a type they compress several times better. The price is that writing one complete row becomes expensive and in-place updates are awkward. That is why these systems load in batches rather than row by row.

وقتی جمع‌بندی دروغ می‌گویدWhen a pre-computed sum lies

برای اینکه هر کوئری مجبور نباشد میلیون‌ها ردیف را بگردد، جدول‌های جمع‌بندی از پیش ساخته می‌شوند. مشکل اینجاست که این جدول‌ها فقط برای سؤال‌هایی که پیش‌بینی کرده‌ای جواب دارند و دادهٔ دیررسیده را هم نمی‌بینند. اگر فروش دیروز بعد از ساخت جمع‌بندی برسد، گزارش ماه با فاکتورها نمی‌خواند و کسی هم نمی‌فهمد چرا. جمع‌بندی باید همیشه از خام بازسازی‌شدنی باشد و تاریخ ساختش کنار عدد نوشته شود، وگرنه یک عدد مطمئن داری که معلوم نیست از کجا آمده.So that every query does not have to walk millions of rows, summary tables are built in advance. The trouble is that those tables only answer the questions you anticipated, and they do not see data that arrived late. If yesterday's sales arrive after the summary was built, the monthly report disagrees with the invoices and nobody can say why. A summary must always be rebuildable from raw, with its build time written next to the number — otherwise you have a confident figure with no known origin.

تلهٔ رایجThe usual trap

اعتماد به جدول‌های جمع‌بندی‌شده به‌عنوان منبع حقیقت. جمع‌بندی شب ساخته می‌شود، دادهٔ دیررسیده را نمی‌بیند، و بعد کسی از گزارش ماهانه تصمیم می‌گیرد. جمع‌بندی باید همیشه از دادهٔ خام بازسازی‌شدنی باشد، وگرنه خودش یک نسخهٔ دوم و اشتباه است.Trusting pre-aggregated tables as the source of truth. The summary is built at night, misses late-arriving data, and then someone makes a decision from the monthly report. A summary must be rebuildable from raw, or it is just a second and wrong copy.

یک ردیف، همین حالا، و بدون اشتباه.One row, right now, and never wrong.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

در صندوق فروشگاه، بارکد یک بستهٔ ماست را می‌زنی: قیمت می‌آید، موجودی یکی کم می‌شود، پول از کارت کم می‌شود و رسید چاپ می‌شود — همه در یک ثانیه و فقط برای همان یک بسته. پردازش تراکنشی همین لحظهٔ کوتاه و دقیق است، نه گزارش سالانه.At the shop till you scan one pot of yoghurt: the price appears, stock drops by one, the card is charged and the receipt prints — all inside a second, all for that one pot. OLTP is that short, exact moment, not the yearly report.

تشبیه و تصویر ذهنیThe analogy

دفتر بلیت‌فروشی یک سالن سینما را در نظر بگیر. دو فروشنده هم‌زمان بلیت می‌فروشند و هیچ‌کدام نباید یک صندلی را دو بار بفروشد. هر بلیت یک خط است، نوشتنش یک ثانیه است، و مشتری همان‌جا ایستاده و نگاه می‌کند؛ اگر سیستم یک لحظه عقب بیفتد یا یک صندلی دو بار ثبت شود، فوراً معلوم می‌شود. همین دفتر برای سؤال «بهار امسال چند بلیت فروختیم» فاجعه است، چون باید صدها صفحه را ورق بزنی. اینجا فقط سرعت و درستی هر بلیت مهم است، نه تحلیل روی همه‌شان.Think of the ticket book at a cinema. Two clerks sell at the same time and neither may sell the same seat twice. Each ticket is one line, writing it takes a second, and the customer is standing there watching; if the system lags a moment or a seat is recorded twice, everyone sees it immediately. That same book is a disaster for “how many tickets did we sell this spring”, because you would turn hundreds of pages. Here only the speed and correctness of each sale matter.

OLTP · لحظهOLTP · the momentکاربر منتظر جوابthe user is waitingچند ردیف با کلیدa few rows by keyدرستی، قبل از هر چیزcorrectness firstOLAP · انبوهOLAP · the bulkتحلیلگر، صبورthe analyst can waitاسکن ستون‌هاa column scanحجم، قبل از تأخیرvolume before latency
دو نگاه به یک داده: یکی یک ردیف را همین حالا می‌خواهد، دیگری همه را برای یک جمع.Two looks at the same data: one wants a row right now, the other wants everything for one total.

و بعدش، فنیAnd now, technically

بار تراکنشی (OLTP) یعنی تعداد زیادی درخواست کوتاه، هر کدام با یک یا چند ردیف که با کلید پیدا می‌شوند. کاربر منتظر است، پس بودجهٔ تأخیر چند میلی‌ثانیه است و هر تأخیر اضافه مستقیماً حس می‌شود. درستی هم قابل مذاکره نیست: تراکنش باید اتمیک باشد، نوشتن پایدار شود و هم‌زمانی با ایزولاسیون مدیریت شود. ذخیره‌سازی ردیفی است و ایندکس‌ها معمولاً درخت B‌اند، چون جست‌وجو با کلید باید با چند پرش تمام شود. گلوگاه از همین‌جا می‌آید: خواندن تصادفی، fsync هر کامیت، و رقابت روی ردیف‌های داغ. اگر همهٔ ترافیک به یک ردیف برسد — مثلاً شمارندهٔ یک محصول پرفروش — هیچ ایندکسی نجاتت نمی‌دهد؛ باید همان ردیف را کمتر لمس کنی یا بشکنی.A transactional load is many short requests, each touching one or a few rows found by key. The user is waiting, so the latency budget is a few milliseconds and every extra one is felt. Correctness is not negotiable either: the transaction must be atomic, the write must be durable, and concurrency must be managed by isolation. Storage is row-oriented and indexes are usually B-trees, because a lookup by key has to finish in a few hops. The bottleneck follows from that: random reads, one fsync per commit, and contention on hot rows. If all traffic lands on one row — the counter of a best-selling product, say — no index saves you; you have to touch that row less or split it.

p99 < 10 msبودجهٔ معمول تأخیر برای یک درخواست تراکنشیa common latency budget for one transactional request
N ≪ 1000هر تراکنش چند رکورد را لمس می‌کند، نه هزار تاa transaction touches a few rows, not a thousand
هزاران/ثانیهتراکنش کوتاه هم‌زمان روی یک گرهshort concurrent transactions on one node

تراکنش کوتاه، تنها راهKeep the transaction short

تراکنش نباید منتظر چیز بیرونی بماند. اگر داخل تراکنش یک API صدا بزنی یا منتظر پاسخ کاربر بمانی، ردیف‌ها قفل می‌مانند، connection اشغال می‌شود، و بقیه پشت سرت صف می‌بندند. قاعدهٔ ساده این است: کارهای بیرونی مثل ایمیل، پرداخت و پیام، بعد از کامیت انجام شوند، نه داخل آن. اگر مجبوری رویداد را هم داخل همان تراکنش ثبت کنی، آن را در یک جدول بنویس و فرستادنش را به یک کارگر جدا بسپار. تراکنش باید به اندازهٔ چند دستور باشد، نه به اندازهٔ یک تجربهٔ کاربری.A transaction must not wait on anything outside itself. Call an API inside it, or wait for the user to answer, and rows stay locked, a connection stays taken, and everyone else queues behind you. The simple rule: outside work such as email, payment and messaging happens after the commit, not inside it. If you must record an event in the same transaction, write it to a table and let a separate worker send it. A transaction should be as long as a few statements, not as long as a user experience.

OLTP در برابر OLAPOLTP versus OLAP

OLTPOLTPOLAPOLAP
شکل درخواستQuery shapeیک ردیف با کلیدone row by keyاسکن و جمع روی انبوهscan and sum over bulk
تعداد ردیفRows touchedچند ردیف در هر کوئریa few rows per queryمیلیون‌ها ردیف در هر کوئریmillions of rows per query
مهم‌ترین چیزWhat matters mostتأخیر و درستی هر تراکنشlatency and correctnessتوان عبور و انعطاف سؤالthroughput and flexible questions
ذخیره‌سازیStorageردیفی، ایندکس درخت Brow layout, B-tree indexesستونی، فشرده، اسکن سریعcolumn layout, compressed

تلهٔ رایجThe usual trap

باز نگه داشتن تراکنش تا وقتی کاربر فرم را پر کند. در آن ثانیه‌ها ردیف قفل است و هر کاربر دیگری که به همان ردیف برسد صف می‌بندد؛ یک کندی کوچک در رابط کاربری تبدیل به قطعی سراسری می‌شود. تراکنش را به اندازهٔ چند دستور نگه دار، نه به اندازهٔ یک تجربهٔ کاربری.Holding a transaction open while the user fills in a form. During those seconds the row is locked and every other user who needs it queues; a small hiccup in the interface becomes a system-wide stall. Keep the transaction as long as a few statements, not as long as a user experience.

پیام رفت بیرون، ولی تراکنش برنگشت.The message left, but the transaction rolled back.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

ایمیل را می‌نویسی و می‌زنی ارسال. پیام از صندوق خروجی می‌رود؛ اگر اینترنت قطع باشد، در همان صندوق می‌ماند و به‌محض وصل شدن دوباره فرستاده می‌شود. صندوق خروجی دیتابیس هم همین است: اول ثبت، بعد ارسال.You write an email and press send. The message leaves the outbox; if the connection drops it stays in that outbox and goes out as soon as the link is back. An outbox in a database is the same thing: record first, deliver after.

تشبیه و تصویر ذهنیThe analogy

در اداره‌ها نامه را اول در دفتر اندیکاتور ثبت می‌کنند و بعد در سینی پست می‌گذارند؛ این دو کار تقریباً یک حرکت است. پستچی بعداً می‌آید، و اگر نامه گم شود از دفتر می‌فهمند چه چیزی فرستاده شده و دوباره می‌فرستند. بهایش این است که نامه تا رسیدن پستچی در سینی می‌ماند، و اگر دوباره فرستاده شود گیرنده باید از شمارهٔ نامه بفهمد که این همان قبلی است. صندوق خروجی دیتابیس دقیقاً همان دفتر و همان سینی است.In an office a letter is first entered in the register and then dropped in the post tray; the two moves are almost one. The postman comes later, and if a letter is lost the register tells you what was sent so you can send it again. The price is that the letter waits in the tray until he comes, and if it goes out twice the recipient has to recognise the reference number. A database outbox is that register and that tray.

تراکنشTransactionردیف + رویدادrow + eventجدول outboxOutbox tableهمان دیتابیسsame databaserelayRelayبه ترتیب idin id orderصف پیامMessage queueحداقل یک بارat least onceمصرف‌کنندهConsumeridempotentidempotent
رویداد اول در همان تراکنش ثبت می‌شود، بعد یک کارگر جدا آن را بیرون می‌برد.The event is recorded inside the transaction first, then a separate worker carries it out.

و بعدش، فنیAnd now, technically

مشکل پایه این است: نوشتن در دیتابیس و فرستادن پیام به broker دو سیستم جدا هستند و تراکنش مشترکی ندارند. اگر دیتابیس کامیت شود و فرستادن شکست بخورد، رویداد برای همیشه گم می‌شود؛ اگر برعکس شود، رویدادی داری که هیچ ردیفی پشتش نیست. راه‌حل outbox این است که ردیف رویداد را در همان دیتابیس و همان تراکنش بنویسی: یک insert در جدول outbox کنار insert سفارش. حالا کامیت یا هر دو را می‌نویسد یا هیچ‌کدام را. بعد یک relay یا یک خوانندهٔ CDC ردیف‌های outbox را به ترتیب id می‌خواند، به صف می‌فرستد و علامت می‌زند. اگر relay بعد از فرستادن و قبل از علامت‌زدن بمیرد، پیام دوباره می‌رود؛ پس تحویل at-least-once است و مصرف‌کننده باید idempotent باشد. ترتیب هم فقط به ازای یک کلید معنا دارد، نه بین کلیدها.The base problem: writing to the database and publishing to a broker are two systems with no shared transaction. If the database commits and the publish fails, the event is lost forever; if the order is reversed you get an event with no row behind it. The outbox answer is to write the event row in the same database and the same transaction: one insert into the outbox table beside the insert of the order. Now the commit writes both or neither. A relay or a CDC reader then reads the outbox rows in id order, publishes them and marks them. If the relay dies after publishing and before marking, the message goes again, so delivery is at-least-once and consumers must be idempotent. Ordering holds per key, never across keys.

1 تراکنشردیف کاری و ردیف رویداد با هم کامیت می‌شوندthe business row and the event row commit together
at-least-onceتحویل تضمینی یک‌بار نیست؛ تکرار ممکن استdelivery may repeat; that is the contract
2 کارنوشتن و فرستادن از هم جدا می‌شوندwriting and sending are split apart

چرا dual write جواب نمی‌دهدWhy dual writes fail

الگوی رایج این است: دیتابیس را به‌روز کن، بعد پیام را بفرست، و اگر خطا داد دوباره تلاش کن. مشکل اینجاست که هیچ ترتیبی از این دو کار درست نیست. اگر اول بنویسی و بعد بفرستی، خرابی بین این دو یعنی رویداد گم‌شده. اگر اول بفرستی و بعد بنویسی، خرابی یعنی رویداد بی‌صاحب. تلاش دوباره هم کمکی نمی‌کند، چون مسئله در خود مرز تراکنش است، نه در تعداد تلاش‌ها. تا وقتی دو سیستم جدا می‌نویسند، همیشه یک پنجره هست که یکی انجام شده و دیگری نه.The usual pattern is: update the database, then publish, then retry on error. The trouble is that neither order works. Write first and publish second, and a crash in between loses the event. Publish first and write second, and a crash leaves an event with no owner. Retrying does not help, because the problem is the transaction boundary itself, not the number of attempts. While two systems write separately there is always a window where one happened and the other did not.

بار اضافه و پاک‌سازیThe extra table and its cleanup

جدول outbox با هر رویداد رشد می‌کند، پس مثل هر جدول دیگری به پاک‌سازی نیاز دارد. اگر بلافاصله پاک کنی، در بازیابی چیزی برای فرستادن نمی‌ماند؛ اگر هیچ‌وقت پاک نکنی، جدول از خود داده بزرگ‌تر می‌شود و ایندکسش هم. سیاست معمول این است که چند روز نگه داری — بیشتر از بلندترین قطعی و عقب‌ترین مصرف‌کننده — و بعد پاک کنی، و همیشه تأخیر relay را اندازه بگیری. جدولی که همیشه خالی است یعنی relay مرده، نه اینکه سیستم سالم است.The outbox table grows with every event, so it needs cleanup like any other table. Delete immediately and a recovery has nothing to send; never delete and the table outgrows the data itself, index included. The usual policy is to keep a few days — longer than the worst outage and the slowest consumer — and then delete, while always measuring relay lag. An always-empty table means a dead relay, not a healthy system.

تلهٔ رایجThe usual trap

نوشتن رویداد بعد از کامیت، با این تصور که outbox داری. اگر insert در outbox بیرون از تراکنش باشد، همان dual write است با یک اسم تازه؛ و اگر relay را با jobی که هر شب اجرا می‌شود راه بیندازی، «بعداً» به «فردا» تبدیل می‌شود و مشتری ایمیلی را که باید همان لحظه می‌رفت، یک روز بعد می‌گیرد.Writing the event after the commit and calling it an outbox. If the insert into the outbox sits outside the transaction, it is the same dual write with a new name; and if the relay is a nightly job, “later” becomes “tomorrow”, and the customer gets the email a day late.

PII

دادهٔ شناسایی‌پذیر شخصی فصل ۱Chapter 1 · دیدن در متنsee in context

چه چیزی روی این برگه هست که نباید اینجا باشد؟What is on this form that has no business being here?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

برگهٔ نوبت مطب روی میز منشی است: اسم، شمارهٔ تلفن و علت مراجعه. هر کسی که در سالن نشسته می‌تواند بخواند. هیچ‌کدام از این سه به‌تنهایی فاجعه نیست، ولی همین که کنار هم بنشینند یک نفر مشخص با یک مشکل مشخص می‌شوند. دادهٔ شناسایی‌پذیر شخصی یعنی همین: داده‌ای که تنها بی‌خطر به نظر می‌رسد و کنار چند تکهٔ دیگر یک آدم را لو می‌دهد.The clinic's appointment slip sits on the reception desk: name, phone number, and why you came. Anyone waiting in the hall can read it. None of the three is a disaster on its own, but side by side they become one identifiable person with one identifiable problem. That is PII: data that looks harmless alone and gives a person away beside a few other pieces.

تشبیه و تصویر ذهنیThe analogy

فکرش را بکن که همین برگه‌ها را یک سال جمع کرده‌ای. هر برگ به‌تنهایی فقط یک نوبت است؛ روی هم که می‌نشینند، الگوی مراجعهٔ یک خانواده و داروی همیشگی‌اش از تویشان در می‌آید. این همان چیزی است که کار را سخت می‌کند: شناسایی‌پذیری ویژگی تک‌تک فیلدها نیست، ویژگی ترکیب آن‌هاست. پس «این ستون حساس نیست» جملهٔ خطرناکی است؛ ستون به‌تنهایی بی‌خطر است، جدولی که ستون در آن نشسته بی‌خطر نیست. و هر جا این داده می‌رود، یک نسخهٔ تازه از مسئله‌اش هم با خودش می‌برد.Imagine collecting those slips for a year. Each one is just an appointment; stacked together they give away a family's pattern of visits and its regular medicine. That is what makes the work hard: identifiability is not a property of each field, it is a property of the combination. So “this column is not sensitive” is a dangerous sentence; the column is harmless, the table it sits in is not. And everywhere this data travels, it carries a fresh copy of the problem with it.

یک رکورد مشتریOne customer recordنام و تلفنname and phoneکد ملیnational IDنشانیaddressسابقهٔ خریدpurchase historyهیچ تکه‌ای تنها کافی نیست؛ کنار هم کافی‌اندno piece is enough alone; together they are
یک رکورد به چند تکه می‌شکند؛ هر تکه به‌تنهایی کم‌ارزش است و کنار هم یک نفر را مشخص می‌کنند.One record splits into pieces; each is worth little alone, and together they name one person.

و بعدش، فنیAnd now, technically

دادهٔ شناسایی‌پذیر شخصی هر اطلاعاتی است که یک فرد را مستقیم یا غیرمستقیم مشخص کند: نام، کد ملی، تلفن و ایمیل مستقیم‌اند؛ تاریخ تولد، کد پستی، جنسیت، شناسهٔ دستگاه و نشانی IP غیرمستقیم، ولی در ترکیب با هم کافی‌اند. کار عملی سه بخش دارد. اول، پیداکردن: هر ستون را طبقه‌بندی کن. دوم، کم کردن: چیزی را که لازم نداری جمع نکن، و در محیط تست و گزارش از دادهٔ پوشانده یا توکن‌شده استفاده کن. سوم، کنترل: دسترسی سطح ردیف و ستون، رمزگذاری در حال ذخیره و انتقال، و ممنوعیت ورودش به لاگ و پیام خطا و کش. سخت‌ترین بخش نسخه‌هاست: همان فیلد در دیتابیس اصلی و در dump شبانه و در دریاچه و در تیکت پشتیبانی و در فایل تست هم هست، و درخواست حذف باید همه را بگیرد. برای داده‌ای که در نسخه‌های فقط-افزودنی نشسته، راه دور انداختن کلید است.Personally identifiable information is anything that identifies a person directly or indirectly: name, national ID, phone and email are direct; birth date, postcode, sex, device ID and IP address are indirect, and sufficient in combination. The practical work has three parts. Find it: classify every column. Reduce it: do not collect what you do not need, and use masked or tokenized data in test and reporting environments. Control it: row- and column-level access, encryption at rest and in transit, and a ban on letting it into logs, error messages and caches. The hard part is copies: the same field sits in the primary database, the nightly dump, the lake, the support ticket and a test fixture, and a deletion request has to reach all of them. For data resting in append-only files, the way out is discarding the key.

3 فیلدتاریخ تولد، کد پستی و جنسیت معمولاً برای شناسایی کافی استbirth date, postcode and sex are usually enough to identify
6 کپیدیتابیس، dump، لاگ، دریاچه، تیکت، محیط تستdatabase, dump, logs, lake, tickets, test env
0 لاگدادهٔ شخصی نباید در لاگ و پیام خطا بیایدpersonal data has no business in logs or error messages

تلهٔ رایجThe usual trap

فرض اینکه PII یعنی همان چند ستون واضح. نشت معمولاً از ترکیب می‌آید: یک ایمیل در پارامتر URL، یک نشانی در پیام خطا، یک جدول تحلیلی که سه فیلد بی‌خطر را کنار هم گذاشته، یا دیتابیس تستی که از تولید کپی شده. توکن‌کردن هم اگر جدول نگاشتش در همان انبار بماند ناشناس‌سازی نیست.Assuming PII is only the obvious columns. The leak usually comes from a combination: an email in a URL parameter, an address in an error message, an analytics table that puts three harmless fields side by side, or a test database copied from production. Tokenizing is not anonymizing either, if the mapping table stays in the same warehouse.

تحلیل که تمام شد، نتیجه کجا باید برود؟The analysis is finished — where does the answer go?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

آخر ماه رسیدها را نگاه می‌کنی و می‌فهمی بیشترین پول خرجِ بیرون غذا خوردن شده. این عدد به‌تنهایی هیچ کاری نمی‌کند؛ باید برگردد به همان چیزی که هر روز با آن زندگی می‌کنی: یک سقف خرج هفتگی در اپ بانک. ETL معکوس همین برگشت است.At the end of the month you look at the receipts and find that most of the money went on eating out. That number does nothing on its own; it has to go back into the thing you live with every day: a weekly spending cap in your banking app. Reverse ETL is that return trip.

تشبیه و تصویر ذهنیThe analogy

تحلیل روی داده‌ای نشسته که ابزار روزمره هیچ‌وقت نمی‌بیند: اپ بانک نمی‌داند ماه گذشته چقدر بیرون غذا خورده‌ای، فقط موجودی امروز را می‌داند. کاری که می‌ماند این است که نتیجه از اتاق تحلیل برگردد به دست کسی که کار را انجام می‌دهد؛ وگرنه یک گزارش زیبا داری که هیچ‌کس بر اساسش کاری نمی‌کند. بهایش این است که داری در ابزاری می‌نویسی که یک انسان هم در آن دست می‌برد: نفر بعدی همان فیلد را عوض می‌کند و همگام‌سازی بعدی حرف او را پاک می‌کند، و اگر کلید هویت دو طرف یکی نباشد، به‌جای به‌روزرسانی رکورد تکراری می‌سازی.The analysis sits on data the daily tool never sees: the banking app does not know how much you ate out last month, only today's balance. What remains is for the result to travel from the analysis back into the hands of the person doing the work; otherwise you own a beautiful report nobody acts on. The price is that you are writing into a tool a human also edits: the next person changes that field and the next sync erases their edit, and if the identity key does not match on both sides you create duplicates instead of updates.

جدول در انبارTable in the warehouseمدل‌شدهmodelledانتخاب بخشPick a segmentمعیار مشخصan explicit ruleکار همگام‌سازیSync jobاز راه APIover the APIابزار روزمرهEveryday toolدست انسانhuman hands
نتیجه از انبار برمی‌گردد به ابزاری که کار واقعی در آن انجام می‌شود؛ جهت، برعکس ETL است.The result travels from the warehouse into the tool where real work happens; the direction is the opposite of ETL.

و بعدش، فنیAnd now, technically

ETL معکوس مسیر برعکس انبار داده است: از جدول‌های مدل‌شدهٔ انبار یک سری رکورد انتخاب می‌شود و از راه API به یک سیستم عملیاتی می‌رود — CRM، میز پشتیبانی، پلتفرم تبلیغات، ابزار صورت‌حساب. اجزایش این‌هاست: یک مدل منبع، که اغلب یک مدل dbt است؛ یک شیء مقصد و نگاشت فیلدها؛ یک کلید هویت مثل ایمیل یا شناسهٔ مشتری؛ یک زمان‌بندی؛ و یک حالت نوشتن مثل upsert یا mirror. چون از API رد می‌شود، سقف واقعی سرعت محدودیت نرخ مقصد است نه توان انبار. خرابی وسط یک دسته رایج است، پس هر همگام‌سازی باید checkpoint و idempotency داشته باشد تا تکرار رکورد تکراری نسازد. تأخیرش در حد دقیقه تا ساعت است و برای رویدادهایی که باید لحظه‌ای به سیستم دیگر برسند مناسب نیست؛ آنجا CDC از دیتابیس عملیاتی جواب می‌دهد.Reverse ETL is the warehouse path run backwards: rows are selected from modelled warehouse tables and pushed through an API into an operational system — a CRM, a support desk, an ad platform, a billing tool. The parts are a source model, often a dbt model; a destination object and a field mapping; an identity key such as email or customer id; a schedule; and a write mode such as upsert or mirror. Because it goes through an API, the real speed cap is the destination's rate limit, not the warehouse's power. A mid-batch failure is routine, so every sync needs checkpoints and idempotency or a retry creates duplicates. Its lag is minutes to hours, which rules it out for events that must reach another system the moment they happen; there, CDC from the operational database is the answer.

1 ساعتدورهٔ معمول یک همگام‌سازی، پس داده همیشه کمی عقب استa typical sync period, so the data is always a little behind
APIمحدودیت نرخ مقصد، سقف واقعی سرعت استthe destination's rate limit is the real speed cap
1 کلیدکلید هویت باید دو طرف یکی باشد، وگرنه رکورد تکراری می‌سازدthe identity key must match on both sides or you get duplicates

تلهٔ رایجThe usual trap

همگام‌سازی دوطرفه بدون تعیین مالک. همان فیلدی که sync می‌نویسد دست فروش هم باز است؛ نتیجه این است که یا ویرایش انسان هر ساعت پاک می‌شود یا دادهٔ انبار با مقادیر دستی آلوده می‌شود. برای هر فیلد باید روشن باشد کدام طرف مالک است، و راه امن معمولاً این است که sync فقط در فیلدهایی بنویسد که کسی دستی عوض نمی‌کند.Two-way syncing with no declared owner. The field the sync writes is also open to a salesperson's edit, so either the human edit is wiped every hour or the warehouse fills with hand-typed values. Each field needs a known owner, and the safe arrangement is usually a sync that writes only into fields nobody edits by hand.

RPO / RTO

هدف نقطه و زمان بازیابی فصل ۱Chapter 1 · دیدن در متنsee in context همچنینalso in فصل ۲ch 2

چقدر داده را می‌توانی ببازی، و چند ساعت بسته بمانی؟How much data may you lose, and how long may you stay closed?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

گوشی‌ات گم شده. آخرین پشتیبان سه هفته پیش بود، پس با خودت می‌گویی «سه هفته عکس را می‌پذیرم» — این RPO توست. و تا گوشی تازه برسد و همه‌چیز برگردد، دو روز بی‌عکس و بی‌شماره سر می‌کنی — این RTO توست. هر دو را قبل از حادثه انتخاب می‌کنی، نه وسطش.You lost your phone. The last backup was three weeks ago, so you tell yourself “I can live with three weeks of photos” — that is your RPO. And until a new phone arrives and everything is back, you spend two days without photos or contacts — that is your RTO. Both are chosen before the incident, not during it.

تشبیه و تصویر ذهنیThe analogy

این دو عدد یک تصمیم‌اند، نه یک اندازه‌گیری، و به دو جهت متفاوت پول می‌برند. RPO کوچک یعنی نسخه‌برداری مکرر یا ارسال پیوستهٔ تغییرها؛ RTO کوچک یعنی یک سیستم آمادهٔ جایگزین، تشخیص خودکار و تمرین واقعی. هر کدام را که کوتاه‌تر کنی، هزینهٔ ماهانه بالا می‌رود. و هر دو با کسب‌وکار توافق می‌شوند، نه در اتاق سرور: «چند سفارش را می‌توانیم از دست بدهیم» سؤال فنی نیست. ضمناً عددی که روی کاغذ نوشته‌ای مهم نیست؛ عددی مهم است که آخرین بار واقعاً اندازه گرفته‌ای.These two numbers are a decision, not a measurement, and they spend money in different directions. A small RPO means frequent copies or changes shipped continuously; a small RTO means a ready replacement, automatic detection and real drills. Shorten either one and the monthly bill goes up. Both are agreed with the business, not chosen in the server room: “how many orders may we lose” is not an engineering question. And the number that matters is not the one on the slide; it is the one you last measured.

آخرین نسخهLast copyپشتیبان دیشبlast nightحادثهFailureساعت ۹ صبح9 a.m.دادهٔ ازدست‌رفتهData lostهمان RPOthat gap is RPOسرویس برگشتBack upهمان RTOthat wait is RTO
فاصلهٔ بین آخرین نسخه و حادثه همان RPO است؛ فاصلهٔ بین حادثه و برگشتن سرویس همان RTO.The gap between the last copy and the failure is RPO; the gap between the failure and service returning is RTO.

و بعدش، فنیAnd now, technically

RPO یا هدف نقطهٔ بازیابی، بیشترین مقدار داده‌ای است که قبول داری از دست برود و با زمان بیان می‌شود: RPO پنج دقیقه یعنی در بدترین حالت پنج دقیقهٔ آخر نوشتن‌ها می‌رود، پس باید تغییرها حداکثر هر پنج دقیقه بیرون بروند یا replication پیوسته باشد. RTO یا هدف زمان بازیابی، بیشترین زمانی است که سرویس می‌تواند جواب ندهد، و معماری را تعیین می‌کند: بازیابی از پشتیبان ساعت‌ها، standby گرم با failover چند دقیقه، و active-active چند ثانیه. RTO واقعی از جمع چند چیز می‌آید: زمان تا تشخیص، زمان تصمیم، زمان failover، و زمان گرم شدن کش‌ها و DNS و استخر اتصال. پشتیبان و replication هم دو چیز متفاوت‌اند: replica تأخیر را کم می‌کند ولی حذف اشتباهی را هم وفادارانه کپی می‌کند، در حالی که پشتیبان تاریخ را نگه می‌دارد.RPO, the recovery point objective, is the most data you accept losing, expressed in time: an RPO of five minutes means the last five minutes of writes can vanish, so changes must leave the system at least every five minutes or replication must be continuous. RTO, the recovery time objective, is the longest the service may be unavailable, and it sets the architecture: restore from backup in hours, a warm standby with failover in minutes, active-active in seconds. Real RTO adds several parts: time to notice, time to decide, time to fail over, and time for caches, DNS and connection pools to warm. Backups and replication are different things: a replica shortens the gap but copies a wrong delete faithfully, while a backup keeps history.

RPO 5mحداکثر داده‌ای که می‌توانی از دست بدهی، بر حسب زمانthe most data you may lose, expressed as time
RTO 1hحداکثر زمانی که سیستم می‌تواند جواب ندهدthe longest the service may be unavailable
2 عددهر دو با کسب‌وکار توافق می‌شوند، نه در اتاق سرورboth are agreed with the business, not in the server room

RPO در برابر RTORPO versus RTO

RPORPORTORTO
چه چیزی را می‌گویدWhat it statesچقدر داده ممکن است برودhow much data may be lostچقدر طول می‌کشد تا برگرددhow long recovery may take
چه چیزی را تعیین می‌کندWhat it drivesفاصلهٔ نسخه‌برداری یا replicationbackup or replication intervalمعماری بازیابی و خودکارسازی failoverrecovery architecture and automation
چطور کم می‌شودHow it shrinksارسال پیوستهٔ تغییرها، نوشتن همزمانcontinuous shipping, synchronous writesstandby گرم، تشخیص و تمرینwarm standby, detection, drills

تلهٔ رایجThe usual trap

نوشتن RPO و RTO در سند و هرگز اندازه نگرفتن. RTO واقعی شامل زمانی است که تا کسی متوجه شود و کسی تصمیم بگیرد، پس «پنج دقیقه» در عمل چهل دقیقه می‌شود؛ و ادعای RPO صفر روی replication غیرهمزمان، به‌طور ساختاری چند ثانیهٔ آخر را از دست می‌دهد.Writing RPO and RTO in a document and never measuring either. Real RTO includes the time until somebody notices and somebody decides, so “five minutes” becomes forty in practice; and claiming an RPO of zero on top of asynchronous replication loses the last few seconds by construction.

سروری که نداری، ولی هر ماه صورت‌حساب دارد.No server of your own, and a bill every month anyway.

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

برای یک قفسهٔ دیوار دریل لازم داری. خریدنش یعنی تا آخر عمر نگهداری‌اش با توست؛ کرایه‌اش یعنی فقط برای یک بعدازظهر پول می‌دهی. ولی هر بار باید در صف گیشه بایستی، ابزار را فقط چند ساعت در اختیارت می‌گذارند، و نمی‌توانی کار نیمه‌تمامت را رویش جا بگذاری. بی‌سرور همین معامله است، با کد جای دریل.You need a drill for one wall shelf. Buying it means maintaining it for the rest of your life; renting it means paying for one afternoon. But each time you queue at the counter, they lend it to you for a few hours only, and you cannot leave your half-finished work attached to it. Serverless is that bargain, with code in place of the drill.

تشبیه و تصویر ذهنیThe analogy

سود این معامله روشن است: هیچ ماشینی نیست که وصله بخورد یا نصف شب از کار بیفتد، و وقتی کسی زنگ نمی‌زند هزینه‌ای نداری. بهایش هم روشن است. هر بار که مدتی کسی صدا نزده، اولین درخواست باید منتظر بماند تا ابزار از انبار بیاید؛ این همان cold start است، از چند صد میلی‌ثانیه تا چند ثانیه. ابزار اجاره‌ای ساعت کاری دارد، پس کاری که بیست دقیقه طول می‌کشد در آن جا نمی‌شود. و چون ابزار را بعد از هر بار پس می‌دهی، هیچ‌چیزت نمی‌تواند رویش بماند: هر حالت باید در یک سرویس بیرونی بنشیند.The gain is obvious: no machine to patch, nothing to fail at midnight, and no cost while nobody calls. The price is obvious too. Whenever nobody has called for a while, the first request waits for the tool to come out of the store; that is the cold start, hundreds of milliseconds to a few seconds. A rented tool has opening hours, so a job that takes twenty minutes does not fit. And because you hand the tool back every time, nothing of yours can stay on it: all state has to live in an external service.

سرور همیشه روشنAlways-on serverماشین مال توستthe machine is yoursبیکار هم پول می‌دهیyou pay while idleتأخیر ثابتsteady latencyتابع بی‌سرورServerless functionبه ازای هر فراخوانیper invocationبیکار، صفرidle, zeroاولین فراخوانی کندthe first call is slow
دو معاملهٔ متفاوت: یکی ماشین را نگه می‌دارد و بیکاری هم پول می‌دهد، دیگری به ازای هر فراخوانی.Two bargains: one keeps a machine and pays while idle, the other pays per invocation.

و بعدش، فنیAnd now, technically

بی‌سرور یعنی کدت را به یک پلتفرم بدهی و پلتفرم به ازای هر فراخوانی اجرا و صورت‌حساب کند؛ ماشینی انتخاب نمی‌کنی و ساعتی پول نمی‌دهی. پشت صحنه، درخواست می‌رسد، پلتفرم یک نمونه روی ماشینی مشترک پیدا می‌کند یا می‌سازد، کد را لود می‌کند، تابع را اجرا می‌کند و بعد نمونه را منجمد یا دور می‌اندازد. cold start همان تأخیر اولین فراخوانی است، وقتی نمونهٔ گرمی وجود ندارد و ساختش گران است؛ نگه‌داشتن نمونهٔ گرم هم پول دارد. سقف‌ها بخشی از طراحی‌اند: حداکثر زمان اجرا، حافظه‌ای که هم‌زمان اندازهٔ CPU را تعیین می‌کند، دیسک موقت محدود، و نبودِ سرور ورودی. چون نمونه‌ها موقتی‌اند، استخر اتصال دیتابیس را نمی‌توانی در حافظهٔ تابع نگه داری؛ یک لایهٔ pooler لازم است، وگرنه موجی از فراخوانی‌های همزمان تعداد اتصال‌های دیتابیس را تمام می‌کند.Serverless means you hand your code to a platform that runs it and bills per invocation; you pick no machine and pay no hourly rate. Behind the scenes a request arrives, the platform finds or creates an instance on a shared machine, loads the code, runs the handler, then freezes or discards the instance. A cold start is the latency of that first invocation when no warm instance exists and building one is expensive; keeping instances warm costs money too. The limits are part of the design: a maximum execution time, a memory size that also sets CPU, a small ephemeral disk, and no inbound server beyond the trigger. Because instances are temporary, a database connection pool cannot live in the function's memory; a pooler layer is required, or a burst of concurrent invocations exhausts the database's connections.

1 درخواستواحد صورت‌حساب، نه ساعت ماشینthe billing unit is one invocation, not machine hours
cold startچند صد میلی‌ثانیه تا چند ثانیه برای اولین درخواستhundreds of milliseconds to seconds on the first call
0 ماشینسروری که خودت نگه داری نداری؛ سقف‌هایش هم دست تو نیستno server of your own, and no say over its limits

تلهٔ رایجThe usual trap

انفجاری که دیتابیس را می‌خواباند. تابع در یک ثانیه هزار برابر می‌شود، دیتابیس نه؛ هزار اتصال باز می‌شود، سقف اتصال پر می‌شود و درخواست‌ها تایم‌اوت می‌دهند. و اگر حالتی را در خود نمونه نگه داری و فرض کنی می‌ماند، فراخوانی بعدی آن را نمی‌بیند؛ نمونه منجمد شده یا رفته است.A fan-out that takes the database down. The function scales a thousandfold in a second, the database does not; a thousand connections open, the limit is hit, and requests time out. And if you keep state in the instance and assume it survives, the next invocation will not see it; the instance was frozen or discarded.

system of record

منبع حقیقت فصل ۱Chapter 1 · دیدن در متنsee in context

وقتی دو سیستم دو چیز می‌گویند، کدام درست است؟When two systems disagree, which one is right?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

وقتی دنبال تاریخ دقیق تولدت هستی، به تقویم گوشی‌ات که کسی دستی پر کرده نگاه نمی‌کنی؛ سراغ شناسنامه می‌روی. پروندهٔ بیمه، فرم مدرسه و پروفایل اپ‌ها همه از روی همان نوشته شده‌اند. اگر جایی با شناسنامه نخواند، آن جا اشتباه است، نه شناسنامه.When you need your exact date of birth you do not check the calendar someone typed into your phone; you go to the birth certificate. The insurance file, the school form, the app profile were all written from it. If something disagrees with the certificate, that something is wrong, not the certificate.

تشبیه و تصویر ذهنیThe analogy

دفتر ثبت اسناد را در نظر بگیر: یک دفتر، یک مأمور، و ساعت کاری محدود. همه از روی همان دفتر کپی برمی‌دارند — دفتر محله، ادارهٔ بیمه، سند فروش — و کپی‌ها همان‌جا مهر می‌شوند. مزیتش این است که وقتی اختلافی پیش می‌آید همه می‌دانند سراغ چه چیزی بروند؛ کافی است یک نفر دفتر را باز کند. بهایش این است که همهٔ تغییرها باید از همان یک جا رد شوند: اگر مأمور مرخص باشد هیچ سندی اصلاح نمی‌شود، و اگر کسی روی یک کپی دست ببرد و آن را درست‌شده بداند، حالا دو روایت داری و باید بنشینی و تطبیق بدهی. همین تطبیق دادن، گران‌ترین کار دنیاست.Think of a land registry: one book, one clerk, limited opening hours. Everyone copies from that book — the local office, the insurer, the sale deed — and the copies are stamped on the spot. The gain is that when a dispute comes up everyone knows where to look; one person opens one book. The price is that every change has to pass through that single point: if the clerk is on leave, nothing gets corrected, and if somebody edits a copy and calls it fixed, you now have two versions of the truth and must sit down and reconcile them. That reconciliation is the most expensive work there is.

نوشتنWriteفقط یک راهone path onlyمنبع حقیقتSystem of recordتنها مرجعthe only authorityنسخه‌های مشتقDerived copiesایندکس، کشindex, cacheمصرف‌کنندهConsumerفقط خواندنread only
اختیار یک طرفه جریان دارد: نوشتن از یک راه، خواندن از چند راه.Authority flows one way: writes from one path, reads from many.

و بعدش، فنیAnd now, technically

برای هر موجودیت — مشتری، سفارش، حساب — یک جا مرجع است، همان system of record: نوشتن فقط از آن مسیر می‌آید و هر چیز دیگری مشتق است. در معماری سرویس‌محور این معمولاً یعنی یک سرویس مالک نوشتن است و بقیه یا از آن می‌خوانند یا از رویدادهایش نسخهٔ خودشان را می‌سازند. مرجع بودن یک ویژگی فنی نیست، یک قرارداد است: اگر دو سیستم بتوانند همان ردیف را بنویسند، تو منبع حقیقت نداری، دو تا داری. هزینه‌اش این است که همان یک جا گلوگاه نوشتن و نقطهٔ وابستگی سخت می‌شود، و هر تغییر schema در آن به همهٔ مصرف‌کننده‌ها می‌رسد. به همین دلیل وسوسهٔ خواندن مستقیم از آن برای گزارش زیاد است، و همان‌جاست که بار تحلیلی روی منبع حقیقت می‌نشیند و تأخیر اپ را خراب می‌کند.For each entity — customer, order, account — one place is the reference: writes come only from that path and everything else is derived. In a service-oriented system that usually means one service owns the writes and the rest either read from it or build their own copy from its events. This authority is not a technical property, it is an agreement: if two systems can write the same row you do not have a system of record, you have two. The cost is that this single place becomes the write bottleneck and a hard dependency, and every schema change there reaches all consumers. That is why reading it directly for reports is so tempting, and why analytical load ends up sitting on the source of truth and ruining application latency.

1 نویسندههر موجودیت فقط از یک جا نوشته می‌شودeach entity is written in exactly one place
N مشتقبقیهٔ نسخه‌ها از همین ساخته می‌شوندevery other copy is built from it
2 → 1دو نویسنده یعنی دو حقیقت؛ یکی باید کنار برودtwo writers mean two truths; one must step back

چرا timestamp نجات نمی‌دهدWhy a timestamp does not save you

راه‌حل رایج برای دو نویسنده این است که هر ردیف یک updated_at داشته باشد و «آخرین نوشتن» برنده شود. این کار در نظر اول منصفانه است و در عمل غلط. ساعت دو ماشین با هم اختلاف دارد، پس «آخر» می‌تواند نوشتهٔ اشتباه باشد. بدتر، دیرتر رسیدن یک پیام هیچ ربطی به درست بودنش ندارد: یک کلیک دیرهنگام روی یک دکمه، درست‌تر از یک تصحیح سریع نیست. last-writer-wins نوشتهٔ درست را هم دور می‌اندازد و این کار را بی‌صدا می‌کند. اگر واقعاً دو نویسنده داری، تصمیم درست یک قاعدهٔ صریح ادغام است، و آن قاعده یک تصمیم محصولی است، نه یک ستون در جدول.The usual fix for two writers is an updated_at on every row and last-writer-wins. It looks fair and it is wrong. Two machines disagree about the time, so “last” can easily be the wrong write. Worse, a message arriving later says nothing about being more correct: a late click on a button is not better than a prompt correction. Last-writer-wins throws away the valid write too, and does it silently. If you genuinely have two writers, the right move is an explicit merge rule, and that rule is a product decision, not a column in a table.

یک نویسنده، چند خوانندهOne writer, many readers

قاعدهٔ عملی این است: یک مسیر می‌نویسد و بقیه فقط می‌خوانند. بقیه می‌توانند از یک replica بخوانند، از یک ایندکس جست‌وجو، یا از رویدادهایی که از منبع بیرون می‌آیند. این قاعده مرز مالکیت را می‌سازد و مرز مالکیت هم چیزی است که تیم‌ها سرش دعوا می‌کنند، چون عملاً می‌گوید کدام سرویس حرف آخر را می‌زند. وقتی این مرز را جابه‌جا می‌کنی — مثلاً سرویس گزارش شروع می‌کند به اصلاح ردیف‌ها — دیگر بحث فنی نیست؛ تو یک منبع حقیقت را دو تکه کرده‌ای و باید یا برگردی یا ادغام را جدی بگیری.The practical rule: one path writes, everything else only reads — from a replica, from a search index, or from events the source publishes. That rule draws the ownership boundary, and ownership boundaries are what teams argue about, because it effectively decides which service has the last word. When you move that boundary — when the reporting service starts correcting rows, say — it stops being a technical debate: you have split one source of truth into two, and you either go back or take merging seriously.

تلهٔ رایجThe usual trap

دو نویسنده روی یک موجودیت و امید به اینکه «آخرین نوشتن» برنده است. last-writer-wins نوشتهٔ درست را هم دور می‌اندازد و بی‌صدا این کار را می‌کند؛ ماه‌ها بعد در گزارش‌ها پیدا می‌شود، وقتی دیگر کسی سابقه‌اش را ندارد.Two writers on one entity and faith in last-writer-wins. It throws the valid write away too, and does it silently; you find out months later in a report, when nobody remembers the original event.

چطور چیزی را پاک کنی که فقط می‌توانی اضافه کنی؟How do you delete something you can only append to?

مثال روزمره، بدون اصطلاحThe everyday one, no jargon

توی دفتر نوبت مطب، وقتی بیماری نوبتش را لغو می‌کند، اسمش را پاک نمی‌کنند؛ جلویش می‌نویسند «لغو شد». اگر پاکش کنند، منشی فردا نمی‌داند این نوبت اصلاً بود یا نه و ممکن است دوباره شماره بدهد. سنگ‌قبر همان «لغو شد» است، در دنیایی که فقط می‌توانی بنویسی.In the clinic's appointment book, when a patient cancels, nobody erases the name; they write “cancelled” in front of it. Erase it and tomorrow the receptionist cannot tell whether that slot ever existed and may hand it out twice. A tombstone is that “cancelled”, in a world where you can only write.

تشبیه و تصویر ذهنیThe analogy

کشوی کاردکس کتابخانه را در نظر بگیر. وقتی کتابی از کتابخانه برداشته می‌شود، کارتش را پاره نمی‌کنند، چون ترتیب کشو به هم می‌خورد و پیدا کردن کتاب‌های دیگر سخت می‌شود. کارت سر جایش می‌ماند و رویش «حذف شد» مهر می‌شود. تا بازنویسی سالانه، این کارت‌ها همان‌جا می‌مانند: کشو از واقعیت بزرگ‌تر است و هر کسی که فهرست را ورق می‌زند کتابی را می‌بیند که در قفسه نیست. اگر یک نسخهٔ قدیمی از فهرست جایی مانده باشد، همان کتاب حتی می‌تواند «برگردد».Think of the card catalogue in a library. When a book is withdrawn, the card is not torn up, because that would break the order of the drawer and make everything else harder to find. The card stays and gets a “withdrawn” stamp. Until the annual rewrite those cards sit there: the drawer is bigger than reality, and anyone reading it sees a book that is not on the shelf. Leave an old copy of the catalogue somewhere and the book can even come back.

حذفDeleteنشانه ثبت می‌شودmarker writtenتکثیرReplicationبه همهٔ نسخه‌هاto every replicaفشرده‌سازیCompactionهر دو پاک می‌شوندboth are dropped
حذف در سه قدم: نوشتن نشانه، رسیدنش به همه‌جا، و پاک‌شدن واقعی در فشرده‌سازی.A delete in three steps: write the marker, let it reach everywhere, drop both for real at compaction.

و بعدش، فنیAnd now, technically

در ذخیره‌سازی لاگ‌محور حذف درجا وجود ندارد؛ تنها کاری که می‌توانی بکنی نوشتن یک tombstone است: همان کلید، یک نشانهٔ حذف و یک نسخه. خواندن باید از روی همهٔ سطح‌ها این نشانه را ببیند و مقدارهای قدیمی‌تر را زیرش بپوشاند، وگرنه رکورد مرده دوباره برمی‌گردد. نشانه مثل هر نوشتن دیگری به همهٔ replicaها تکثیر می‌شود. تا وقتی فشرده‌سازی به آن سطح برسد، هم نشانه و هم مقدارهای پوشانده‌شده سر جایشان می‌مانند و فضا می‌گیرند، و اسکن‌ها کندتر می‌شوند چون باید نشانه‌های بیشتری را رد کنند. فشرده‌سازی فقط وقتی می‌تواند هر دو را دور بریزد که هیچ replica عقب‌افتاده‌ای، هیچ snapshot قدیمی و هیچ مصرف‌کننده‌ای به آن نسخه نیاز نداشته باشد؛ به همین دلیل یک دورهٔ مهلت لازم است. اگر نشانه را زود پاک کنی، ریپلیکایی که با دادهٔ قدیمی برمی‌گردد رکورد را دوباره زنده می‌کند.In log-structured storage there is no delete in place; all you can do is write one more record: the same key, a deletion marker, a version. A read must see that marker across every level and shadow the older values underneath it, or the dead record comes back. The marker replicates like any other write. Until compaction reaches that level, both the marker and the shadowed values stay on disk and take space, and scans slow down because they must step over more markers. Compaction may drop both only when no lagging replica, no old snapshot and no consumer still needs that version, which is why a grace period exists. Delete the marker too early and a replica returning with old data brings the record back to life.

1 نشانهجای حذف درجا، یک رکورد «حذف شد» نوشته می‌شودinstead of an in-place delete, one deleted record
> lagعمر نشانه باید از عقب‌ترین replica بیشتر باشدa tombstone must outlive the slowest replica
TTLبعضی انبارها برای نشانه تاریخ انقضا می‌گذارندsome stores put an expiry on tombstones

تا کی باید بماندHow long it has to stay

عمر نشانه را می‌شود با یک قاعدهٔ ساده حساب کرد: تا وقتی که آخرین نسخهٔ ممکن از دادهٔ قدیمی بتواند برگردد. یعنی بیشتر از بلندترین قطعی و عقب‌ماندگی replica، بیشتر از عمر طولانی‌ترین snapshot، و بیشتر از زمانی که بازیابی یک پشتیبان طول می‌کشد. اگر نشانه‌ها را با TTL پاک می‌کنی، آن TTL باید از همهٔ این‌ها بزرگ‌تر باشد، وگرنه دقیقاً در همان سناریویی که برایش آماده شده‌ای، دادهٔ حذف‌شده برمی‌گردد. بهای این مهلت طولانی هم فضا و کندی اسکن است؛ همان معاملهٔ همیشگی بین درستی و هزینه.The lifetime follows one simple rule: until the oldest possible copy of the data can no longer come back. That means longer than the worst outage and the slowest replica, longer than the longest-running snapshot, and longer than a backup restore takes. If tombstones expire on a TTL, that TTL must exceed all of these, or the deleted row returns in exactly the scenario the tombstone existed for. The price of a long grace period is space and slower scans, the usual trade between correctness and cost.

وقتی حذف باید واقعاً حذف باشدWhen a delete has to be a real delete

بعضی وقت‌ها مهلت جواب نمی‌دهد: قانون می‌گوید داده باید در یک مهلت مشخص واقعاً از بین برود، و تو نمی‌توانی ماه‌ها صبر کنی تا فشرده‌سازی برسد و پشتیبان‌ها هم کهنه شوند. راهی که این کار را ممکن می‌کند رمزگذاری به ازای هر کاربر است: داده با یک کلید رمز می‌شود و برای حذف، کلید را دور می‌ریزی. آن‌وقت نشانه‌ها لازم نیست سریع پاک شوند، چون داده بدون کلید فقط بایت است. شرطش این است که همهٔ نسخه‌ها — پشتیبان، replica، فایل‌های پارک‌شده — با همان کلید رمز شده باشند، وگرنه یک نسخهٔ بدون کلید پیدا می‌شود و کل ماجرا بی‌اثر است.Sometimes a grace period is not good enough: the law says the data must really be gone by a deadline, and you cannot wait months for compaction and for old backups to age out. The way out is encryption per user: encrypt the data under one key and delete the key when you must delete the data. Then the tombstones no longer have to disappear quickly, because without the key the bytes mean nothing. The condition is that every copy — backup, replica, archive — used the same key, otherwise one unencrypted copy turns up and the whole arrangement is worthless.

تلهٔ رایجThe usual trap

پاک کردن نشانه چون «جا می‌گیرد»، چند ساعت بعد از نوشتنش. ریپلیکایی که یک روز عقب بود برمی‌گردد، رکورد مرده را دوباره می‌بیند و زنده‌اش می‌کند؛ و این را ماه‌ها بعد در گزارش مشتریان می‌فهمی، وقتی کسی نمی‌داند این رکورد از کجا آمده.Dropping tombstones a few hours after writing them because they take up space. A replica that was a day behind comes back, sees the dead record again and restores it to life — and you learn it months later from a customer report, with nobody able to say where that record came from.