۳۳ واژه از فصل ۲ — هر کدام با یک مثال روزمره، یک نمودار و تلهٔ رایج.33 terms from chapter 2, each with an everyday example, a diagram and the usual trap.
چند دقیقه در ماه را میشود «همیشه» نامید؟How many minutes a month still counts as always-on?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
آسانسور ساختمان دهطبقهتان سالی سه چهار ساعت از کار میافتد. طبقهٔ دوم تو همان سه ساعت را با پله جبران میکنی و تا شب فراموشش میکنی. همسایهٔ طبقهٔ دهم با عصا همان سه ساعت را باید پله بالا برود و تا آخر سال از آن حرف میزند. دسترسپذیری همین است: نه درصدی که در گزارش مینویسی، بلکه زمانی که یک آدم واقعی نمیتواند کارش را انجام دهد.The lift in your ten-storey building is out for three or four hours a year. From the second floor you take the stairs and forget it by dinner. The neighbour on the tenth floor, on a cane, spends those same three hours on the stairs and brings it up for the rest of the year. That is availability: not the percentage in the report, but the minutes when one real person cannot do the thing they came to do.
تشبیه و تصویر ذهنیThe analogy
عدد دسترسپذیری از یک قرار ساده میآید: زمانی که سیستم جواب میدهد، تقسیم بر کل زمانی که کسی از او انتظار جواب دارد. سه یا چهار ۹ یعنی در ماه چند ده دقیقه قطعی، و پنج ۹ یعنی در سال چند دقیقه. این عدد را معمولاً از سمت خودت اندازه میگیری و همانجا اشتباه شروع میشود؛ از سمت کاربر، سیستم وقتی قطع است که صفحهاش باز نمیشود، و این ممکن است تقصیر تو نباشد. آسانسور هم همین شکل است: موتور سالم است ولی کارت طبقهٔ دهم را نمیخواند، و برای آن همسایه آسانسور خراب است. به همین دلیل بعضی تیمها دسترسپذیری را با یک معاملهٔ واقعی میسنجند: یک کاربر ساختگی که هر دقیقه همان مسیر اصلی خرید را میرود، نه یک ping به یک آدرس.The number comes from one simple deal: the time the system answers, divided by the time anyone expected an answer. Three or four nines means tens of minutes of outage a month; five nines means minutes a year. And you usually measure it from your own side, which is where the mistake starts. From the user side the system is down when the page will not open, and that may not be your fault. The lift is the same: the motor is fine, but it will not read a tenth-floor card, and for that neighbour the lift is broken. That is why some teams measure availability with a real transaction instead of a ping: a synthetic user who walks the main purchase path every minute.
هر پله یک خرابی بیشتر را میپوشاند و یک هزینهٔ تازه اضافه میکند؛ پایین ارزان و شکننده، بالا گران و کمشکننده.Each rung covers one more failure and adds one more cost: cheap and brittle low down, dear and steady up top.
و بعدش، فنیAnd now, technically
در عمل، دسترسپذیری روی یک پنجرهٔ زمانی حساب میشود: ۹۹.۹٪ در سی روز یعنی حدود ۴۳ دقیقه قطعی مجاز در ماه، و ۹۹.۹۹٪ یعنی حدود چهار دقیقه. اما عدد یک سرویس، عدد مسیر کاربر نیست. اگر صفحهٔ تو به سه سرویس وابسته باشد که هر کدام ۹۹.۹٪ هستند و پشت سر هم صدا زده میشوند، حاصل تقریباً ۹۹.۷٪ میشود، یعنی حدود دو ساعت در ماه؛ یک وابستگی تازه میتواند عدد کل سال را خراب کند. برای بالا بردن عدد سه کار جواب میدهد: حذف نقطهٔ تکخرابی با نسخهٔ دوم در یک failure domain دیگر، کوتاه کردن زمان تشخیص و جابهجایی، و کم کردن تعداد وابستگیهای مسیر اصلی. هر سه هزینه دارند و هر سه خرابی تازهٔ خودشان را میآورند: نسخهٔ دوم باید هماهنگ بماند و خود جابهجایی چند ثانیه قطعی است. بالاتر از چهار یا پنج ۹، گلوگاه دیگر سختافزار نیست؛ خودِ فرایند تغییر است، چون هر دیپلوی و هر ریاستارت باید بدون قطعی انجام شود.In practice availability is computed over a window: 99.9% across thirty days leaves about 43 minutes of allowed outage a month, and 99.99% leaves about four. But one service's number is not the user's path. If your page depends on three services that are each 99.9% and it calls them in sequence, the product is about 99.7%, roughly two hours a month, and one new dependency can spoil the whole year. Three moves raise the number: remove single points of failure with a second copy in another failure domain, shorten detection and switchover, and cut the number of dependencies on the critical path. All three cost money and all three bring new failure modes: the second copy must stay in sync, and the switchover itself is a few seconds of outage. Past four or five nines the bottleneck is no longer hardware; it is change, because every deploy and every restart now has to happen without a pause.
99.9%حدود ۴۳ دقیقه قطعی مجاز در ماهabout 43 minutes of allowed outage a month
99.99%حدود چهار دقیقه در ماه؛ هر ۹ اضافه، ده برابر سختترabout four minutes a month; each extra nine is ten times harder
3 × 99.9%زنجیرهٔ سه سرویس تقریباً ۹۹.۷٪ میشود، نه ۹۹.۹٪three services in series give about 99.7%, not 99.9%
چرا «بالا بودن» با «کار کردن» یکی نیستWhy up is not the same as working
یک health check ساده فقط میگوید پروسه زنده است. سرویسی میتواند کد ۲۰۰ بدهد و همزمان هیچ سفارشی ثبت نکند، چون پایگاه دادهاش رفته یا صف پشت سرش چهل دقیقه عقب افتاده است. برای کاربر این حالت با قطعی فرقی ندارد؛ برای داشبورد تو سبز است. به همین دلیل تعریف «کار کردن» باید از مسیر کاربر بیاید: یک درخواست واقعی که چند رکورد میخواند و یک رکورد آزمایشی مینویسد و بعد پاکش میکند. فاصلهٔ این دو تعریف، همان فاصلهٔ بین «سرویس بالاست» و «مشتری میتواند بخرد» است.A simple health check only says the process is alive. A service can return 200 while no order is being saved, because its database is gone or its queue is forty minutes behind. For the user that is indistinguishable from an outage; for your dashboard it is green. So the definition of working has to come from the user's path: a real request that reads a few rows, writes one test row, and deletes it again. The gap between the two definitions is the gap between the service being up and the customer being able to buy.
دسترسپذیری را از کجا اندازه بگیریWhere to measure it
عدد دسترسپذیری به نقطهٔ اندازهگیری وابسته است. اگر از لودبالانسر بشماری، خرابی خودِ برنامه را میبینی ولی کندی شبکهٔ کاربر را نمیبینی؛ اگر از سمت کاربر بشماری، همه چیز را میبینی ولی نمیدانی تقصیر کیست. دو حساب رایج هم داری: حساب زمانی، یعنی چند دقیقه از ماه بالا بودی، و حساب درخواستی، یعنی چند درصد از درخواستها موفق بود. اولی برای گزارش مدیریت خوب است و دومی به تجربهٔ کاربر نزدیکتر. هر کدام را انتخاب کنی، یک چیز را از قبل روشن کن: تعمیرات برنامهریزیشده در مخرج هستند یا نه. اگر بیرونشان بگذاری و در همان حال به مشتری «همیشه» بگویی، عددی ساختهای که خودت هم باورش نمیکنی.The number depends on the measurement point. Count at the load balancer and you see application failures but not a slow client network; count at the user and you see everything but cannot tell whose fault it is. There are two books as well: time-based, the minutes you were up, and request-based, the share of requests that succeeded. The first is good for a management report, the second is closer to what a user feels. Whichever you pick, settle one thing up front: whether planned maintenance sits in the denominator. Exclude it while promising customers always-on and you have built a number you do not believe yourself.
دسترسپذیری در برابر قابلیت اطمینانAvailability versus reliability
دسترسپذیریAvailability
قابلیت اطمینانReliability
سؤال اصلیThe question
الان جواب میدهد؟does it answer right now?
مدتها درست کار میکند؟does it keep working correctly?
بیشتر تیمها دسترسپذیری را از health check خودشان میشمارند؛ همان آدرسی که فقط میگوید پروسه بالاست. اگر پایگاه داده رفته باشد و کش هنوز جواب بدهد، آن آدرس سبز میماند و گزارش تو ۹۹.۹۹٪ نشان میدهد در حالی که کاربر هیچ چیزی نمیتواند بخرد. دام دوم تعریف مخرج است: اگر پنجرههای بیترافیک را حذف کنی یا تعمیرات را بیرون بگذاری، عدد زیبا میشود و هیچکس حسش نمیکند.Most teams count availability from their own health check, the address that only says the process is alive. If the database is gone and the cache still answers, that address stays green and your report shows 99.99% while the user can buy nothing. The second trap is the denominator: drop the windows with no traffic, or move maintenance outside the sum, and the number turns pretty and nobody feels it.
دو نسخه در یک ساختمان، یعنی چند نسخه؟Two copies in one building: how many copies is that?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
داروخانهٔ محله یک شعبه دارد و سردخانهاش به برق همان خیابان وصل است. شب طوفان برق میرود و همهٔ داروها خراب میشوند. اگر شعبهٔ دیگری آنطرف شهر داشت طوفان هر دو را نمیگرفت، ولی حالا باید دو سردخانه، دو داروساز و دو بار موجودی نگه دارد؛ منطقهٔ دسترسپذیری همان شعبه است، با همان حساب و کتاب.The neighbourhood pharmacy has one branch and its cold store runs on the same street's power. A storm takes the power out one night and all the medicine spoils. A second branch across town would not have been hit by the same storm, but it means two cold stores, two pharmacists and two sets of stock; an availability zone is that branch, with the same arithmetic.
تشبیه و تصویر ذهنیThe analogy
دو شعبه وقتی کمک میکنند که خرابیشان به هم ربط نداشته باشد. اگر هر دو از یک انبار مرکزی دارو بگیرند، خرابی انبار هر دو را با هم میخواباند و دو شعبه فقط هزینهٔ بیشتر بوده. اگر هر دو در یک خیابان باشند، همان یک ترکیدگی لوله هر دو را میبندد. افزونگی جغرافیایی وقتی معنا دارد که سؤال «چه چیزی میتواند هر دو را با هم از کار بیندازد؟» جواب نداشته باشد، و آن جواب معمولاً چیزی است که در دیاگرام نیست.Two branches help only when their failures are unrelated. If both take stock from one central warehouse, the warehouse takes both down and the second branch was just extra cost. If both sit on the same street, one burst pipe closes both. Geographic redundancy means something only when the question what could take both down at once has no answer, and that answer is usually something that is not in the diagram.
یک منطقه ساده و سریع است با ریسک مشترک؛ چند منطقه تحمل خرابی میدهد، با تأخیر و هزینهٔ بیشتر.One zone is simple and fast with shared risk; several zones buy fault tolerance at more latency and cost.
و بعدش، فنیAnd now, technically
منطقهٔ دسترسپذیری، واحد زیرساختی داخل یک منطقه است: برق، خنککننده، شبکه و سالن جدای خودش را دارد و طوری ساخته شده که یک خرابی موضعی (آتش، سیل، قطع فیبر، خاموشی برق) حداکثر یکی را ببرد. برنامهٔ مقاوم نسخههایش را روی دستکم دو منطقه پخش میکند و ظرفیت را طوری میچیند که با رفتن یک منطقه، باقی از عهدهٔ بار بربیاید. تکرار داده داخل یک منطقه معمولاً همگام است چون تأخیر چند میلیثانیهای است؛ بین منطقهها ناهمگام یا نیمههمگام. قیمتش را در ترافیک بین منطقهها، تأخیر بیشتر و پیچیدگی استقرار میدهی.An availability zone is an infrastructure unit inside a region: its own power, cooling, network and halls, built so that a local failure such as fire, flood, fibre cut or blackout takes at most one of them. A resilient application spreads its copies over at least two zones and sizes capacity so that the rest can carry the load when one is gone. Replication inside a zone is usually synchronous because the latency is a few milliseconds; across zones it is asynchronous or semi-synchronous. You pay for it in cross-zone traffic, extra latency and harder deployments.
2–3تعداد معمول منطقهها در یک منطقهٔ ابری بزرگa common number of zones in a large cloud region
1 zoneظرفیت را طوری بچین که رفتن یک منطقه را تحمل کندprovision capacity to survive one zone going away
تلهٔ رایجThe usual trap
گذاشتن نسخهٔ اصلی و نسخهٔ دوم در یک منطقه، به بهانهٔ تأخیر کمتر؛ همان منطقه که برود هر دو با هم میروند. اشتباه دوم، فرض کردن این است که چند منطقه در برابر خرابی کل منطقه محافظت میکند.Putting the primary and its replica in the same zone for lower latency; when that zone goes, both go. The second mistake is assuming zones protect you from a whole-region failure.
چرا همان جواب را دوباره حساب میکنی؟Why compute the same answer twice?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
بقال سر کوچه یک سینی کوچک پشت صندوق دارد: شکر، چای، سیگار، پاکت شیر. هر کس یکی از اینها را بخواهد، دو ثانیهای جواب میگیرد. بقیهٔ جنسها در انبار پشت مغازهاند و رفتوبرگشتش دو دقیقه است. آن سینی همان کش است: چیزهایی که زیاد پرسیده میشوند، دم دست؛ و انبار، همان پایگاه داده.The corner shop keeps a small tray behind the till: sugar, tea, cigarettes, a carton of milk. Anyone who wants one of those is served in two seconds. Everything else sits in the back room, two minutes there and back. The tray is the cache: the things people ask for constantly, kept within reach. The back room is the database.
تشبیه و تصویر ذهنیThe analogy
این سینی سه محدودیت دارد و هر سه دربارهٔ کش هم درستاند. اول، جا: سینی کوچک است، پس فقط چیزی میماند که مرتب پرسیده شود؛ وقتی جنس تازهای محبوب شد، یکی باید از سینی بیرون برود، و اگر اشتباه انتخاب کنی مشتریها را راهی انبار میکنی. دوم، تازگی: اگر قیمت شکر در انبار عوض شود و برچسب روی سینی عوض نشود، مغازهدار جواب دارد ولی جواب کهنه میدهد؛ کش هم میتواند جواب داشته باشد و آن جواب کهنه باشد، فقط با داده و بیآنکه کسی متوجه شود. سوم، لحظهٔ شلوغی: اگر سینی خالی شود و ده نفر همزمان شیر بخواهند، هر ده نفر راه میافتند طرف انبار و انباری که برای یک نفر ساخته شده زیر ده نفر میخوابد. این همان stampede است.The tray has three limits and all three are true of a cache. Room: the tray is small, so only what is asked for often stays; when something new becomes popular, something else has to leave, and a bad choice sends customers to the back room. Freshness: if the price of sugar changes in the back room and the label on the tray does not, the shopkeeper has an answer but it is the old one — a cache does the same, with data. Rush hour: if the tray runs empty and ten people want milk at once, all ten walk to the back room, and a back room built for one person collapses under ten. That is a stampede.
هر درخواست اول به کش میخورد؛ فقط miss به پایگاه داده میرسد و جوابش کش را پر میکند.Every request hits the cache first; only a miss reaches the database, and its answer refills the cache.
و بعدش، فنیAnd now, technically
کش یعنی نسخهٔ دومی از داده که ممکن است کهنه باشد، و همین «ممکن است کهنه باشد» تعریف کل ماجراست. هر نگاه به کش یا hit است یا miss؛ hit ratio همان نسبتی است که هزینهٔ کل را تعیین میکند و برای بیشتر سرویسها ۹۵ تا ۹۹ درصد است. کش را در چند جا میشود گذاشت و هر جا قرارداد کهنگی خودش را دارد: در پروسهٔ خود سرویس که سریعترین است ولی هر نسخه کش خودش را دارد، در یک سرویس مشترک مثل Redis با یک رفتوبرگشت شبکه، یا در CDN دمِ لبه. سه راه رایج برای تازه نگه داشتن: TTL که بعد از چند ثانیه خودش را دور میریزد، write-through که نوشتن را از کش هم عبور میدهد، و کلید نسخهدار که دادهٔ تازه را زیر کلید تازه مینشاند و کهنه را رها میکند تا خودش برود. کش اندازه دارد: وقتی پر شد باید چیزی را بیرون بیندازی، معمولترین قاعده LRU است، و انتخاب بد یعنی hit ratio پایین و بار برگشته روی پایگاه داده.A cache is a second copy of data that may be stale, and that clause is the whole story. Every lookup is a hit or a miss, and the hit ratio decides the total cost; for most services it sits between 95% and 99%. You can place the cache in several spots, each with its own staleness contract: inside the service process, which is fastest but gives every replica its own copy; in a shared service such as Redis, one copy for everyone at the price of a network round trip; or at the edge in a CDN. Three common ways to keep it fresh: a TTL that discards it after a few seconds, write-through that pushes writes through the cache, and versioned keys that put fresh data under a fresh key and let the old one age out. A cache has a size: when it fills, something must be evicted, LRU is the usual rule, and a bad choice shows up as a low hit ratio and the load back on the database.
~0.5 msپاسخ از کش در همان دیتاسنترa cache answer inside the same datacenter
~10–50 msهمان پرسوجو از پایگاه داده زیر بارthe same query from the database under load
95–99%hit ratio معمول یک کش سالمthe usual hit ratio of a healthy cache
کهنه بودن یک تصمیم است، نه یک اتفاقStaleness is a decision, not an accident
هر کشی بالاخره کهنه میشود؛ سؤال این است که کهنگیاش چقدر مجاز است و برای چه کسی. یک قرارداد ساده بنویس: کاربر باید نوشتن خودش را ببیند، ولی شمارندهٔ بازدید یک پست را میشود چند ثانیه کهنه نشان داد. بعد برای هر دسته عدد خودش را انتخاب کن: قیمت و موجودی کوتاه، متن پروفایل بلند. دام اینجاست که کسی میگوید «پس TTL را یک ثانیه میکنیم که هیچوقت کهنه نباشد»؛ با این کار تقریباً همهٔ درخواستها miss میشوند، کش بیفایده میشود و بار کامل برمیگردد روی پایگاه داده. راه بهتر، باطل کردن هدفمند است: هر نوشتن، کلید مربوط به خودش را حذف میکند و بقیه به حال خود میمانند.Every cache goes stale eventually; the question is how much staleness is allowed and for whom. Write a simple contract: a user must see their own write, but a post's view counter can be a few seconds behind. Then pick a number per class of data: short for price and stock, long for profile text. The trap is the person who says: let us set the TTL to one second and it will never be stale. With that, almost every request is a miss, the cache does nothing, and the full load returns to the database. Targeted invalidation is the better move: each write deletes its own key and leaves the rest alone.
وقتی کش خالی میشودWhen the cache goes empty
دو لحظه هست که کش از کمککننده به خطر تبدیل میشود. اول، شروع سرد: بعد از دیپلوی یا ریاستارت، کش خالی است و همهٔ ترافیک یکباره به پایگاه داده میرود؛ اگر پایگاه داده برای آن بار ساخته نشده باشد، همان لحظه میخوابد. دوم، انقضای همزمان: اگر کلید پرطرفداری منقضی شود، همهٔ درخواستهای آن کلید با هم به عقب میروند. سه درمان ساده وجود دارد: یکی کردن درخواستهای همزمان برای یک کلید تا فقط یکی به عقب برود، پخش کردن زمان انقضا با کمی تصادف، و گرم کردن کش پیش از آوردن نود تازه به گردش.Two moments turn a cache from a helper into a hazard. The cold start: after a deploy or a restart the cache is empty and all traffic goes to the database at once; if the database was not sized for that, it falls over right then. Simultaneous expiry: when one popular key expires, every request for it goes back at the same moment. Three simple remedies: coalesce concurrent requests for one key so only one goes back, spread expiry times with a little jitter, and warm the cache before a fresh node takes traffic.
کش کنارِ پایگاه داده در برابر نوشتن از طریق کشCache-aside versus write-through
cache-asidecache-aside
write-throughwrite-through
خواندنRead
اول کش، بعد پایگاه دادهcache first, then the database
کش تقریباً همیشه پر استthe cache is almost always warm
نوشتنWrite
در پایگاه داده، بعد حذف کلید کشto the database, then delete the key
هم در کش هم در پایگاه دادهto both, in one step
کهنگیStaleness
ممکن است، ولی کوتاهpossible, but short
کمتر، به بهای نوشتن کندترrarer, at the cost of slower writes
هزینهCost
کد بیشتر، کنترل بیشترmore code, more control
سادگی، ولی هر نوشتن دو جاsimpler, but every write touches two places
تلهٔ رایجThe usual trap
اگر داده فقط در کش باشد، کش شده پایگاه داده و دیگر کش نیست: با ریاستارت یک نود، بخشی از داده برای همیشه میرود. خطای دوم، نوشتن بدون باطل کردن است؛ کاربر شمارهاش را عوض میکند، صفحهٔ بعد همان شمارهٔ قدیمی را نشان میدهد و او فکر میکند ثبت نشده.If data lives only in the cache, the cache has become the database and is no longer a cache: restart one node and part of the data is gone for good. The second error is writing without invalidating; a user changes their phone number, the next page shows the old one, and they conclude it was never saved.
اگر امشب یکی از سرورها بمیرد، چه کسی میفهمد؟If a server dies tonight, who finds out?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
هیچوقت منتظر آتشسوزی واقعی نمیمانی تا بفهمی راه پله بنبست است. یک عصر زنگ تمرین را میزنند و همه از پلهها پایین میآیند؛ در طبقهٔ سوم در قفل است و همه برمیگردند. همان تمرین در قفلشده را پیدا کرد، نه آتش؛ مهندسی آشوب هم همان تمرین است، با خرابیهای ساختگی و از پیش تعیینشده.You never wait for a real fire to find out the stairwell is a dead end. One evening the drill bell goes and everyone walks down, and on the third floor the door is locked and everyone turns back. The drill found the locked door, not the fire; chaos engineering is that drill, with failures that are artificial and chosen in advance.
تشبیه و تصویر ذهنیThe analogy
تمرین قواعدی دارد. اعلامشده یا سرزده، ولی همیشه با یک ناظر، یک مسیر خروج و یک علامت توقف. اگر همزمان دو راه پله را ببندی، چیزی یاد نمیگیری جز اینکه آدمها عصبانی میشوند. اگر تمرین همیشه خوب پیش برود مشکوک است؛ احتمالاً مسیری را انتخاب کردهای که بلدی از آن رد شوی. تمرین خوب آن است که یک چیز واقعی را لو بدهد و بعد کسی آن را درست کند.A drill has rules. Announced or not, it always has a warden, a way out and a stop signal. Block both stairwells at once and you learn nothing except that people get angry. A drill that always goes well is suspicious; you probably picked a route you already know how to walk. A good drill gives away one real thing, and then somebody fixes it.
یک آزمایش، پنج قدم: اول بگو چه انتظاری داری، آخرش بنویس چه یاد گرفتی.One experiment, five steps: state the expectation first, write down what you learned last.
و بعدش، فنیAnd now, technically
مهندسی آشوب یعنی یک آزمایش کنترلشده طراحی کنی: یک فرضیه («اگر یک منطقه از دست برود، تأخیر صدک ۹۹ زیر فلان میماند»)، یک معیار حالت پایدار، یک شعاع اثر کوچک، و یک شرط توقف. بعد خرابی را تزریق میکنی: کشتن یک پردازه، کند کردن شبکه، پر کردن دیسک، منقضی کردن گواهی، یا قطع یک مسیر. تفاوتش با خرابکاری همین است: فرضیه و توقف و ثبت نتیجه دارد. اگر مشاهدهپذیریات ضعیف باشد، آزمایش فقط یک حادثهٔ واقعی تولید میکند.Chaos engineering means designing a controlled experiment: a hypothesis (if one zone is lost, p99 latency stays under such and such), a steady-state metric, a small blast radius and a stop condition. Then you inject the fault: kill a process, slow the network, fill a disk, expire a certificate, cut a link. That is what separates it from vandalism: a hypothesis, a stop, and a written result. If your observability is weak, the experiment just manufactures a real incident.
1در هر آزمایش یک متغیر را عوض کن، نه پنج تاchange one variable per experiment, not five
تلهٔ رایجThe usual trap
کشتن چیزهای تصادفی در تولید و اسمش را گذاشتن آزمایش. بدون فرضیه، بدون دامنهٔ اثر، بدون توقف، چیزی که تولید میکنی حادثه است نه دانش. بدتر، آزمایشی که فقط مسیر اصلی را میسنجد و fallback را امتحان نمیکند به تو میگوید سیستم سالم است، در حالی که نسخهٔ پشتیبان ماههاست خراب است.Killing random things in production and calling it an experiment. Without a hypothesis, a blast radius and a stop condition, what you produce is an incident, not knowledge. Worse, a test that only checks the main path and never touches the fallback tells you the system is healthy while the standby has been broken for months.
چه کسی تعیین میکند هر درخواست کجا برود؟Who decides where each request should go?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
چراغ چهارراه خراب شده و یک پلیس وسط خیابان ایستاده و با دست به ماشینها میگوید کدام صف راه بیفتد. وقتی شیفتش تمام میشود، ماشینها همچنان میروند و کسی گیر نمیکند؛ ولی اگر همان شب یک آمبولانس از خیابان کناری برسد، کسی نیست که مسیر را باز کند. پلیس همان لایهٔ کنترل است: خودش باری حمل نمیکند، جای بار را تعیین میکند.The traffic light at the junction is dead and an officer stands in the middle, waving cars through one queue at a time. When his shift ends the cars keep moving and nobody is stuck; but if an ambulance comes down the side street that night, there is nobody to open a path. The officer is the control plane: he carries no traffic, he decides where it goes.
تشبیه و تصویر ذهنیThe analogy
سه چیز دربارهٔ همان پلیس درست است و هر سه به لایهٔ کنترل مربوطاند. اول، او ترافیک را حمل نمیکند؛ فقط اجازه میدهد یا نمیدهد، پس اگر تصمیمش دیر برسد ماشینها بدون او هم میروند، فقط بد میروند. دوم، دیدش کامل نیست: کامیونی جلوی دیدش ایستاده و صف پشت سرش را نمیبیند، پس بر اساس واقعیتی تصمیم میگیرد که چند دقیقه کهنه شده. سوم، اگر دو پلیس با دو دستور مخالف وسط یک چهارراه بایستند، نتیجه قفل شدن کامل است؛ در سیستمهای توزیعشده به این حالت split brain میگویند. برای همین لایهٔ کنترل معمولاً محافظهکار است: وقتی مطمئن نیست تصمیم تازه نمیگیرد و همان وضع موجود را نگه میدارد.Three things are true of that officer and all three belong to the control plane. He carries no traffic, he only permits or forbids, so when his decisions arrive late the cars still move, just badly. His view is incomplete: a truck blocks his line of sight and he cannot see the queue behind it, so he decides on a picture that is minutes old. And if two officers stand in one junction giving opposite orders, the result is a deadlock — in distributed systems, split brain. That is why a control plane is conservative: when it is unsure it stops making new decisions and keeps the current state.
حلقهٔ کنترل حالت مطلوب را با واقعیت مقایسه میکند و فقط تفاوت را به لایهٔ داده میفرستد.The control loop compares the desired state with reality and sends only the difference to the data plane.
و بعدش، فنیAnd now, technically
لایهٔ کنترل حالت مطلوب را نگه میدارد و دنیای واقعی را به سمتش میبرد: چند نسخه باید باشد، کدام نود leader است، ترافیک به کدام آدرس برود، کدام shard روی کدام ماشین بنشیند. این کار یک حلقهٔ ساده است: حالت مطلوب را بخوان، وضعیت واقعی را مشاهده کن، تفاوت را حساب کن، و یک تغییر کوچک به لایهٔ داده بفرست. چون این تصمیمها باید بین چند نود توافق شوند، لایهٔ کنترل معمولاً روی مجموعهٔ کوچکی از نودها با تعداد فرد مینشیند که با consensus کار میکنند؛ سه یا پنج نود، نه دویست نود. نکتهٔ کلیدی این است که ترافیک کاربر از این لایه نمیگذرد: اگر لایهٔ کنترل بخوابد، درخواستهای جاری معمولاً ادامه پیدا میکنند، ولی هیچ چیز تازهای اصلاح نمیشود؛ نود خراب جایگزین نمیشود، ظرفیت بالا نمیرود، و جابهجایی رخ نمیدهد. برعکسش هم خطرناک است: اگر همان ترافیک سنگین از لایهٔ کنترل بگذرد، یک کندی کوچک آن را میخواباند و بعد سیستم دیگر نمیتواند خودش را درمان کند.A control plane holds the desired state and drives the real world toward it: how many replicas should exist, which node is the leader, which address traffic should reach, which shard belongs on which machine. The work is a simple loop: read the desired state, observe the actual state, compute the difference, send one small change to the data plane. Because those decisions must be agreed between nodes, a control plane usually runs on a small, odd-sized set of nodes using consensus — three or five, not two hundred. The key property is that user traffic does not pass through it: when the control plane is down, in-flight requests usually keep working, but nothing new gets repaired; a dead node is not replaced, capacity does not grow, and no failover happens. The reverse is just as dangerous: push heavy traffic through the control plane, and one small slowdown takes it down, after which the system can no longer heal itself.
3–5نودهای کنترل؛ عدد فرد تا رأی اکثریت ممکن باشدcontrol nodes, an odd number so a majority can vote
0 req/sترافیک کاربری که باید از آن بگذردuser traffic that should pass through it
تصمیم کهنه از تصمیم نگرفتن خطرناکتر استA stale decision is worse than none
تصمیم لایهٔ کنترل روی اطلاعاتی بنا میشود که همیشه کمی عقب است؛ heartbeat هر چند ثانیه میرسد و بین دو تا، دنیا عوض میشود. اگر لایهٔ کنترل بر اساس یک فهرست کهنه بگوید «این نود مرده است» و بار را جابهجا کند، ممکن است نود واقعاً زنده باشد و حالا دو جا خودشان را مسئول بدانند. به همین دلیل جابهجایی باید با یک نشانهٔ افزایشی همراه باشد: نسخهٔ تازهای از مسئولیت که نود قدیمی آن را ندارد و نمیتواند بنویسد. لایهٔ کنترل خوب، آن است که وقتی دیدش کامل نیست، تصمیم را عقب میاندازد، نه اینکه سریعترین حدس را اجرا کند.A control plane decides on information that is always slightly behind: heartbeats arrive every few seconds, and the world changes in between. If it reads an old list, declares a node dead and moves the load, the node may be alive and now two places believe they are in charge. That is why promotion has to carry an increasing token: a version of responsibility the old node does not hold and cannot write under. A good control plane, when its view is incomplete, delays the decision instead of executing its fastest guess.
خودش یک سیستم توزیعشده استIt is a distributed system itself
لایهٔ کنترل مشکل توزیعشدهٔ خودش را دارد: باید بین چند نود توافق کند، رهبر انتخاب کند، و در برابر همان خرابیهایی مقاوم باشد که قرار است مدیریت کند. اگر روی همان شبکه و همان منطقهٔ لایهٔ داده بنشیند، در همان لحظهای که باید نود خراب را جابهجا کند، خودش هم در دسترس نیست. به همین دلیل جدایش میدهند: شبکهٔ مدیریت جدا، منطقهٔ جدا، و تعداد نود کم تا توافق سریع باشد. هزینهاش این است که خودِ ارتقای لایهٔ کنترل پرخطرترین دیپلوی سال میشود، چون همهٔ تصمیمهای خودکار به آن وابستهاند.A control plane has its own distributed problem: it must agree among nodes, elect a leader, and survive the very failures it is meant to manage. Put it on the same network and the same zone as the data plane and, at the moment it needs to route around a dead node, it is unreachable itself. So teams separate it: its own management network, its own zone, few enough nodes that agreement stays fast. The price is that upgrading the control plane becomes the riskiest deploy of the year, because every automatic decision depends on it.
تلهٔ رایجThe usual trap
اگر لایهٔ کنترل همان شبکه و همان منطقهٔ لایهٔ داده را داشته باشد، در همان لحظهای که باید نود خراب را جابهجا کند خودش هم در دسترس نیست. خطای دوم، گذاشتن یک پرسوجوی هماهنگی در مسیر هر درخواست است: یک بار که آن سرویس کند شود کل ترافیک کند میشود و چیزی که باید فقط تصمیم بگیرد خودش گلوگاه شده.Put the control plane in the same network and zone as the data plane and, at the very moment it must route around a dead node, it is unreachable too. The second error is a coordination lookup on the path of every request: once that service slows down, all traffic slows down, and the thing that was only supposed to decide has become the bottleneck.
وقتی پنل مدیریت بالا نمیآید، سرویس هنوز کار میکند؟The admin panel is down. Is the service still serving?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
در صف نانوایی کارت میکشی. اگر دفتر مرکزی بانک در آن لحظه درست کار نکند، خرید کوچک هنوز انجام میشود، چون دستگاه سقف و قاعدهٔ از پیش گرفتهٔ خودش را دارد. اگر خود دستگاه یا خط فروشگاه قطع شود هیچ خریدی انجام نمیشود، هرقدر هم دفتر مرکزی سالم باشد؛ لایهٔ داده همان لحظهٔ خرید است و لایهٔ کنترل همان دفتری که قاعدهها را عوض میکند.You tap your card at the bakery queue. If the bank's head office is having a bad minute the small purchase still goes through, because the terminal holds its own ceiling and rule from before. If the terminal itself or the shop's line goes down, nothing goes through however healthy the head office is; the data plane is the moment of purchase, the control plane is the office that changes the rules.
تشبیه و تصویر ذهنیThe analogy
این جدایی از روی تنبلی نیست؛ از روی تجربه آمده. اگر هر خرید باید از دفتر مرکزی اجازه بگیرد، یک کندی در دفتر مرکزی همهٔ صفها را میخواباند. پس دستگاه با آخرین قاعدهای که گرفته کار میکند و بعداً حسابها را تسویه میکند. بهایش این است که قاعدهٔ جدید تا وقتی دستگاه بهروز نشود اثر نمیکند، و اگر کسی سقف را عوض کند چند دقیقه دو دنیای مختلف داری.This split is not laziness; it comes from experience. If every purchase had to ask head office for permission, one slow moment there would stop every queue. So the terminal runs on the last rule it received and settles the accounts later. The price is that a new rule does nothing until the terminal is updated, and if someone changes a ceiling you briefly live in two different worlds.
دو مسیر با دو وظیفه: یکی ترافیک را حمل میکند، دیگری میگوید ترافیک کجا برود.Two paths, two jobs: one carries the traffic, the other decides where it goes.
و بعدش، فنیAnd now, technically
لایهٔ داده مسیر داغ سیستم است: هر درخواست، هر خواندن و هر نوشتن که حجمش با ترافیک بالا میرود. لایهٔ کنترل چیزهایی را که کم پیش میآیند و پر اثرند مدیریت میکند: پیکربندی، مسیرها، جایگذاری، گواهیها، و اینکه کدام نسخه کجاست. قاعدهٔ طراحی این است که لایهٔ داده به لایهٔ کنترل وابسته نباشد، بلکه آخرین نسخهٔ سالم پیکربندی را کنار خودش نگه دارد. اگر لایهٔ داده برای هر درخواست از لایهٔ کنترل بپرسد، جدایی از بین میرود و یک قطعی کوچک در پیکربندی به قطعی کل ترافیک تبدیل میشود.The data plane is the system's hot path: every request, every read and every write, its volume scaling with traffic. The control plane manages the rare, high-impact things: configuration, routes, placement, certificates, and which version runs where. The design rule is that the data plane must not depend on the control plane for each request; it keeps the last good configuration beside it. If the data plane asks the control plane on every request, the split is gone and a small configuration outage becomes an outage of all traffic.
تلهٔ رایجThe usual trap
پرسیدن از لایهٔ کنترل در مسیر هر درخواست. یک بار این کار راحت است، تا روزی که آن سرویس ده ثانیه کند شود و کل ترافیک پشت آن بایستد. اشتباه دوم، فرستادن پیکربندیای است که لایهٔ داده نمیتواند اعتبارسنجی کند؛ یک مسیر غلط همهٔ پروکسیها را با هم میشکند.Asking the control plane on the path of every request. It is convenient once, until that service hangs for ten seconds and all traffic queues behind it. The second mistake is pushing configuration the data plane cannot validate: one bad route breaks every proxy at once.
چقدر میشود خراب شد و کسی چیزی نگوید؟How much can you break before anyone minds?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
اینترنت گوشیات بیست گیگ در ماه است. دو هفتهٔ اول عادی ویدیو میبینی؛ اواخر ماه نگاه میکنی چقدر مانده و اگر نزدیک صفر بود ویدیو را قطع میکنی و فقط پیام میخوانی. هیچکس به تو نگفته «بد مصرف کن» یا «خوب مصرف کن»؛ یک عدد بوده که معلوم میکند کِی باید دست از کار تازه بکشی. بودجهٔ خطا همان گیگشمار است، برای خرابی سرویس.Your phone plan gives you twenty gigabytes a month. For two weeks you watch video as usual; late in the month you check what is left, and if it is nearly zero you stop the video and only read messages. Nobody told you to use it badly or well; there was just a number that showed when to stop spending. An error budget is that counter, for failures.
تشبیه و تصویر ذهنیThe analogy
سه چیز در همان گیگشمار هست که در بودجهٔ خطا هم تکرار میشود. اول، نرخ خرج کردن مهم است، نه فقط باقیمانده: اگر سه گیگ را در دو روز بسوزانی، حتی با هفده گیگ باقیمانده رفتار عوض میکنی؛ در سرویس هم نرخ سوختن است که هشدار میدهد، نه رسیدن به صفر. دوم، بیمصرف ماندن هم علامت است: اگر هر ماه نصف بسته باقی میماند، یا بسته زیادی گرفتهای یا عادتت عوض شده؛ سرویسی که هرگز به هدفش نزدیک نمیشود احتمالاً هدف را زیادی محافظهکارانه چیده و پول اضافه میدهد. سوم، قاعده را از قبل مینویسی: «اگر تا روز بیستم سهچهارم رفت، ویدیو را کم میکنم.» تیمها هم همان را مینویسند: با ۸۰ درصد مصرف، انتشار ویژگی تازه متوقف میشود.Three things about that counter are also true of an error budget. The burn rate matters, not just the remainder: burn three gigabytes in two days and you change behaviour with seventeen still left; in a service it is the burn rate that raises the alarm, not hitting zero. Not spending is also a signal: if half the plan is left every month, you bought too much or your habits changed — a service that never comes close to its target probably set it too conservatively and is paying for nothing. And you write the rule in advance: if three quarters are gone by the twentieth, the video goes. Teams write the same rule: at 80% consumed, new feature releases stop.
سهم هر هفته از بودجهٔ خطای یک ماه: سه هفته آرام، و یک هفته که تقریباً همهاش را میخورد.Each week's share of one month's error budget: three calm weeks, then one that eats almost all of it.
و بعدش، فنیAnd now, technically
بودجه از یک تفریق میآید: اگر هدف ۹۹.۹٪ باشد، سهم خطای مجاز ۰.۱٪ است، چه در قالب درصد درخواست حسابش کنی چه در قالب زمان. میشود دو دفتر جدا داشت: دفتر درخواستی میگوید از هر هزار درخواست یکی میتواند خراب شود، دفتر زمانی میگوید در ماه چند دقیقه. هشدارها معمولاً روی نرخ سوختن تنظیم میشوند: سوختن ۱۴ برابرِ حالت عادی در یک ساعت یعنی تقریباً دو درصد از بودجهٔ ماه در همان یک ساعت رفته و این ارزش بیدار کردن آدم را دارد. مهمترین بخش، قاعدهٔ تصمیم است: وقتی بودجه تمام شد، انتشار ویژگی تازه و تغییرات پرخطر متوقف میشود و ظرفیت مهندسی میرود روی درست کردن. همین قاعده بحث «این خرابی مهم بود یا نه» را از جلسه بیرون میآورد، چون از قبل روی عدد توافق شده است. بودجه روی معیاری مینشیند که کاربر حسش میکند، نه روی درصد مصرف CPU.The budget is a subtraction: if the target is 99.9%, the allowed failure share is 0.1%, whether you count requests or time. Keep two books: the request book says one in a thousand may fail, the time book says how many minutes a month. Alerts usually run on the burn rate: burning 14 times the normal rate for an hour spends about 2% of the month's budget in that hour, which is worth waking someone for. The decisive part is the rule: when the budget is gone, new features and risky changes stop and engineering time goes to repair. That rule takes the argument about whether this outage mattered out of the meeting, because the number was agreed in advance. And the budget is attached to a metric the user feels, not to CPU percentage.
1 − SLOبودجه همان فاصلهٔ هدف تا کمال استthe budget is the gap between the target and perfect
0.1%سهم خطای مجاز در هدف ۹۹.۹٪the allowed failure share at a 99.9% target
14.4×سوختنی که در یک ساعت دو درصد بودجهٔ ماه را میبردa burn rate that spends 2% of the month in one hour
بودجه چه چیزی را نمیپوشاندWhat the budget does not cover
بودجه دربارهٔ خطاهای سنجیدهشده روی یک معیار است و همینجا مرزش تمام میشود. از دست رفتن داده را نمیپوشاند: اگر یک بکاپ خراب باشد و کسی نفهمد، درصد موفقیت درخواستها همچنان عالی است تا روزی که لازمش داری. جواب غلط و بیصدا را هم نمیپوشاند؛ سرویسی که بهجای خطا، عدد اشتباه برمیگرداند، همهٔ درخواستهایش «موفق» است و بودجه هیچ چیزی نمیبیند. امنیت و حریم داده هم بیرون این حساباند، چون هزینهشان با درصد درخواست اندازهگیری نمیشود. برای همین کنار بودجه، دو چیز دیگر لازم است: یک معیار درستی جدا، و یک عدد جدا برای دادهٔ از دست رفته.A budget is about errors measured on one metric, and that is where it ends. It does not cover data loss: if a backup is broken and nobody knows, the request success rate stays excellent until the day you need it. It does not cover quiet wrongness either: a service that returns a wrong number instead of an error has a hundred percent of successful requests, and the budget sees nothing. Security and privacy sit outside it too, because their cost is not measured in percent of requests. So beside the budget you need two more things: a correctness signal of its own, and a separate number for lost data.
چه کسی بودجه را خرج میکندWho spends it
بودجه مال تیمی است که همان معیار را میسازد و همان تیم باید اختیار توقف انتشار را داشته باشد. اگر بودجه را یک تیم زیرساخت نگه دارد و تیم محصول خرجش کند، هیچ اتفاقی نمیافتد؛ عدد در داشبورد میماند و انتشار سر جایش. یک اثر جانبی خوب هم دارد: اوایل ماه که بودجه پر است، میشود تغییر پرخطر را با خیال راحتتر فرستاد و آخر ماه محافظهکارتر بود. ولی همان اثر، دام هم میشود: اگر قاعده فقط «تا وقتی بودجه هست، بفرست» باشد، تیم یاد میگیرد تا آخرین قطره بخورد و بعد یک تغییر کوچک، بودجهٔ ماه بعد را هم بسوزاند.The budget belongs to the team that owns the metric, and that team needs the authority to stop releases. If infrastructure guards the budget while product spends it, nothing happens: the number stays on a dashboard and the release goes out anyway. There is a good side effect: early in the month, with the budget full, a risky change can ship with less argument, and late in the month you are more careful. But that same effect is a trap: if the only rule is ship while there is budget, a team learns to spend down to the last drop, and then one small change burns next month too.
تلهٔ رایجThe usual trap
بودجهای که فقط در داشبورد است، بودجه نیست. اگر قاعدهٔ «با تمام شدن بودجه انتشار متوقف میشود» جایی نوشته نشده و کسی اختیار اجرایش را ندارد، تیم همان انتشار را میفرستد و عدد به یک اسلاید تبدیل میشود. خطای دوم، گذاشتن بودجه روی معیاری است که کاربر حسش نمیکند: کد ۲۰۰ از لودبالانسر در حالی که صفحه سفید میماند، بودجه را تازه نگه میدارد و اعتماد را میسوزاند.A budget that lives only on a dashboard is not a budget. If the rule that releases stop when it runs out is written nowhere and nobody has the authority to enforce it, the team ships anyway and the number becomes a slide. The second error is measuring it where the user is not: a 200 from the load balancer while the page stays blank keeps the budget fresh and burns trust.
فردا شرط تازهای اضافه میشود؛ باید خانه را خراب کرد؟A new requirement lands tomorrow. Rebuild the whole house?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
با آجرهای خانهسازی یک خانه ساختهای و کلی هم چسباندهای. فردا میخواهی یک اتاق اضافه کنی: چهار آجر را برمیداری، اتاق را میچینی و بقیهٔ خانه دست نمیخورد. اگر همهچیز را با چسب یکتکه کرده بودی، برای یک اتاق باید کل خانه را میشکستی؛ تحولپذیری همین است: طراحیای که تغییرِ فردا را ارزان کند.You built a house out of building blocks and glued a good part of it. Tomorrow you want one more room: you lift four blocks, add the room, and the rest of the house stays put. If you had glued the whole thing into one piece, one room would mean breaking the house — evolvability is a design that makes tomorrow's change cheap.
تشبیه و تصویر ذهنیThe analogy
دو خانه را در نظر بگیر. اولی را با چسب یکتکه ساختهای و محکم است. دومی را با آجرهای استاندارد ساختهای و کمی لقتر است، ولی میتوانی طبقه اضافه کنی، پنجره را جابهجا کنی یا یک اتاق را کامل برداری. هیچکدام مطلقاً بهتر نیست: خانهٔ چسبی تا وقتی هیچچیز عوض نشود محکمتر و ارزانتر است. تحولپذیری همین معامله را با تو میکند: مرزهای روشن و رابطهای استاندارد میخری تا تغییر بعدی هزینهٔ بازسازی کل را نداشته باشد. بهایش این است که رابط را از اول درست انتخاب کنی، چون عوض کردن خودِ رابط، همان شکستن خانه است.Picture two houses. The first is glued into a single piece and it is solid. The second is built from standard blocks: a little looser, but you can add a floor, move a window, or take a whole room away. Neither is simply better: the glued house is stronger and cheaper as long as nothing changes. Evolvability offers the same bargain: you buy clear boundaries and standard joints so the next change does not cost a rebuild. The price is that you must pick the joint well at the start, because replacing the joint itself is the same as breaking the house.
خانهٔ چسبی تا وقتی چیزی عوض نشود محکمتر است؛ خانهٔ قطعهقطعه تغییر بعدی را ارزان میکند.The glued house is stronger while nothing changes; the modular one makes the next change cheap.
و بعدش، فنیAnd now, technically
در کتاب، تحولپذیری یعنی بشود سیستم را آسان تغییر داد و با نیازهای تازه سازگار کرد؛ و چیزی که واقعاً این را میسازد مرز است، نه نیت خوب. سه چیز بیشترین اثر را دارند: رابط مشخص بین بخشها، قالب دادهٔ نسخهدار، و جدا کردن انتشار از استقرار. در داده، معنیاش سازگاری دوطرفه است: کد قدیمی باید دادهٔ تازه را بخواند و کد تازه باید دادهٔ قدیمی را بفهمد، وگرنه در آپدیت غلتان چند دقیقهای همهچیز میشکند. برای تغییرهای بزرگ، الگوی گسترش-مهاجرت-جمعشدن جواب میدهد: اول ستون یا فیلد تازه را اضافه میکنی، مدتی هر دو را مینویسی، داده را پُر میکنی، و فقط بعد قدیمی را برمیداری. این کار کند است، ولی هیچ لحظهای در آن کد قدیمی و جدید با هم ناسازگار نیستند. تحولپذیری را نمیشود بعداً و ارزان به سیستم اضافه کرد؛ مثل همان رابط، از اول یا هست یا نیست.In the book, evolvability means the system can be modified and adapted to new requirements easily, and what actually buys it is boundaries, not good intentions. Three things matter most: explicit interfaces between parts, versioned data formats, and separating release from deploy. In data it comes down to two-way compatibility: old code must read new data and new code must understand old data, or a rolling upgrade breaks for a few minutes in the middle. For large changes, expand-migrate-contract works: add the new column, write both for a while, backfill, and only then remove the old one. It is slow, but at no point do old and new code disagree about the shape of the data. And you cannot bolt evolvability on cheaply later; like the joint, it is either there from the start or it is not.
N ↔ N+1در آپدیت غلتان، دو نسخهٔ کد همزمان روی همان داده کار میکنندduring a rolling upgrade, two code versions work on the same data
تلهٔ رایجThe usual trap
اشتباه گرفتن تحولپذیری با «هر چیزی را میشود عوض کرد». اگر هر بخش آزاد باشد به جدول و ستون بقیه دست بزند، هر تغییر کوچک به یک بازنویسی تبدیل میشود. مرزِ سخت، تغییر را آسان میکند، نه آسانگیری.Mistaking evolvability for “anything can be changed”. If every part may reach into everyone else's tables and columns, each small change becomes a rewrite. Hard boundaries make change easy; permissiveness does not.
وقتی leader میمیرد، کی تصمیم میگیرد جانشین کیست؟When the leader dies, who decides who takes over?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
مسیر تهران تا مشهد را با دو راننده میروید: یکی رانندگی میکند، یکی خواب است. سر بینراهی عوض میکنید و این ساده است، چون هر دو بیدار و آمادهاند و ماشین ایستاده. ولی اگر رانندهٔ اول وسط جاده حالش بد شود، عوض کردن روی شانهٔ جاده انجام میشود، ماشین چند دقیقه میایستد، و رانندهٔ دوم نقشهٔ همان ده کیلومتر آخر را ندارد. failover همان لحظه است: جانشین آماده، ولی همیشه با کمی تأخیر و کمی کمبود اطلاعات.You drive Tehran to Mashhad with two drivers: one at the wheel, one asleep. You swap at a rest stop, and that part is easy because both are awake, ready, and the car is parked. But if the first driver falls ill in the middle of the road, the swap happens on the hard shoulder, the car stands still for a few minutes, and the second driver does not know the last ten kilometres. Failover is that moment: a ready replacement, always with a little delay and a little missing information.
تشبیه و تصویر ذهنیThe analogy
همان سفر سه درس دارد. اول، جابهجایی برنامهریزیشده با ناگهانی فرق دارد: عوض کردن در بینراهی هیچ هزینهای ندارد، چون از قبل هماهنگ شده و هر دو میدانند نوبت کی است؛ در سیستم به آن switchover میگویند و معمولاً بدون قطعی است. دوم، یک نفر باید تشخیص بدهد راننده واقعاً نمیتواند ادامه بدهد: اگر زود قضاوت کنی رانندهٔ سالم را کنار میگذاری و مسافرها بیدلیل میایستند، و اگر دیر بفهمی ممکن است دیر شده باشد. سوم، خطر واقعی این است که هر دو همزمان فرمان را بگیرند؛ در سیستم به آن split brain میگویند و از توقف بدتر است، چون دو نفر همزمان مسیر را عوض میکنند.That trip holds three lessons. A planned swap is not an unplanned one: changing at a rest stop costs nothing because it was agreed and both know whose turn it is — in a system that is a switchover, and it is usually seamless. Someone has to decide the driver really cannot continue: judge too early and you park a healthy driver while passengers stop for nothing; judge too late and it may be too late. And the real danger is both grabbing the wheel at once — split brain — which is worse than standing still, because two people change the route at the same time.
بازهٔ بین «ضربان قطع شد» و «کلاینت مسیر تازه را پیدا کرد» همان قطعیای است که کاربر حس میکند.The gap between the heartbeat stopping and clients finding the new route is the outage the user feels.
و بعدش، فنیAnd now, technically
failover یعنی وقتی نسخهٔ اصلی از کار میافتد، نسخهٔ دیگری کار را بردارد و بقیه هم قبول کنند که او حالا مسئول است. سه تکه دارد و هر تکه میتواند خراب شود. تشخیص: با heartbeat و timeout میفهمی نود رفته؛ timeout کوتاه تشخیص را سریع میکند، ولی زیر بار نود سالم را مرده اعلام میکنی و بار روی بقیه میافتد. انتخاب: یا جانشین از قبل تعیین شده، یا رأی اکثریت لازم است تا دو نود همزمان خودشان را leader ندانند. هدایت دوبارهٔ کلاینتها: آدرس، DNS یا VIP باید عوض شود و کش کلاینتها هم باطل شود، وگرنه درخواستها همچنان به نود مرده میروند. اگر تکثیر async بوده، جانشین چند نوشتن آخر را ندارد و پنجرهٔ از دست رفتن داده به اندازهٔ همان تأخیر است. برای همین هر leader باید یک fencing token داشته باشد تا نود قدیمی که دوباره بیدار شده نتواند بنویسد.Failover means that when the primary goes down, another copy takes the work and everyone agrees it is now in charge. It has three parts and each can fail. Detection: heartbeats and timeouts tell you a node is gone; a short timeout detects fast, but under load you will declare a healthy node dead and dump its load on the rest. Election: either a standby was appointed in advance, or a majority vote is required so two nodes do not both call themselves leader. Redirection: the address, DNS record or VIP must change and client caches must be invalidated, or requests keep going to the dead node. If replication was async, the promoted copy lacks the last few writes and the data-loss window equals the replication lag. That is why every leader must hold a fencing token, so the old node cannot write when it wakes up.
5–30 sزمان معمول تشخیص و جابهجایی در سرویسهای مدیریتشدهtypical detect-and-promote time on managed services
2–3ضربان از دست رفتهٔ لازم برای اعلام مرده؛ کمترش false positive میدهدmissed heartbeats before declaring death; fewer gives false positives
≥ lagبا تکثیر async، نوشتنهای نرسیده میروند؛ پنجرهٔ از دست رفتن به اندازهٔ lag استwith async replication, unreplicated writes are lost; the window equals the lag
تشخیص، سختترین تکه استDetection is the hard part
نودی که جواب نمیدهد لزوماً مرده نیست؛ ممکن است فقط کند باشد، یا شبکهاش شلوغ باشد، یا خودش در صف GC گیر کرده باشد. از بیرون این سه حالت یکجور دیده میشوند و همین، کار را سخت میکند. timeout کوتاه یعنی نود کند را مرده میبینی، بار را روی بقیه میریزی، بقیه هم کند میشوند، و یک کندی کوچک به فروپاشی زنجیرهای تبدیل میشود. timeout بلند یعنی کاربر بیشتر منتظر میماند و جابهجایی کند است. راه معقول، اندازهگیری توزیع واقعی زمان پاسخ و انتخاب عددی بیرون از دنبالهٔ کند است، بههمراه کم کردن بار بهجای تلاش دوبارهٔ بیحساب.A node that does not answer is not necessarily dead; it may merely be slow, or its network congested, or it may be stuck in a garbage collection pause. From outside all three look alike, which is what makes this hard. A short timeout means you read a slow node as dead, shift its load, the rest get slow too, and a small slowdown becomes a cascading failure. A long timeout means users wait longer and failover drags. The sane path is to measure the real response-time distribution, pick a value outside the slow tail, and shed load instead of retrying blindly.
بعد از جابهجایی، سیستم همان سیستم قبلی نیستAfter failover it is not the same system
جانشین تازه، همه چیز را نمیداند: کشش سرد است، اتصالهایش هنوز گرم نشده، و اگر تکثیر async بود چند نوشتن آخر را ندارد. بعضی کلاینتها آدرس قدیمی را در حافظه دارند و تا منقضی شدن DNS همچنان به نود مرده میزنند. و اگر leader قدیمی برگردد، ممکن است با دادهٔ کهنه دوباره خودش را مسئول بداند. به همین دلیل جابهجایی یک تمرین است، نه یک دکمه: باید چند بار در محیط آزمایشی و در ساعت کاری کم انجام شود، زمان واقعیاش اندازهگیری شود، و برگشتن به حالت اول هم مثل یک جابهجایی دیگر تمرین شود.The new leader does not know everything: its cache is cold, its connections are not warm, and if replication was async it lacks the last few writes. Some clients hold the old address and keep hitting the dead node until DNS expires. And if the old leader comes back, it may believe it is in charge again with stale data. That is why failover is a drill, not a button: run it several times in staging and at a quiet hour, measure the real time it takes, and rehearse the way back as another failover.
تلهٔ رایجThe usual trap
کوتاه کردن timeout برای «سریع بودن» رایجترین دام است: نودِ کند اما سالم مرده اعلام میشود، بار روی بقیه میافتد، بقیه هم کند میشوند و آنها هم مرده اعلام میشوند؛ یک کندی کوچک به فروپاشی زنجیرهای تبدیل میشود. دام دوم، جابهجایی بدون fencing است: leader قدیمی برمیگردد و چون هیچکس جلویش را نگرفته، چند نوشتن متناقض ثبت میکند.Shortening the timeout to look fast is the classic trap: a slow but healthy node is declared dead, its load moves, the rest slow down and get declared dead too, and a small slowdown becomes a cascade. The second trap is failover without fencing: the old leader comes back, nobody stops it, and it writes a few contradictory records.
یک خرابی از کجا تا کجا را با خودش میبرد؟How far does one failure reach before it stops?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
در ساختمانتان برای هر واحد یک فیوز جدا گذاشتهاند: اتوی واحد شما میسوزد، فیوز همان واحد میپرد و بقیه در روشنایی میمانند. اگر همهٔ واحدها یک فیوز مشترک داشتند، یک اتو کل ساختمان را تاریک میکرد. دامنهٔ خرابی یعنی همین مرز: بزرگترین دستهای که با هم میایستد.Every flat in your building has its own fuse: a faulty iron in your flat trips your fuse, and the neighbours keep their lights on. If the whole building shared one fuse, a single iron would black out everyone. A failure domain is that boundary: the largest group that goes down together.
تشبیه و تصویر ذهنیThe analogy
این مرزها تودرتو هستند: فیوز اتاق، فیوز طبقه، کلید اصلی ساختمان. خرابی در سطح پایین فقط همان واحد را میگیرد، ولی خرابی در سطح بالا همه را. حالا نکتهٔ ظریف: مرز فقط وقتی کار میکند که خرابی از آن بالاتر نرود. اگر سیمکشی همهٔ واحدها را یک نفر در یک هفته کشیده باشد، احتمالاً یک ایراد مشترک هم دارند و مرز فقط روی کاغذ است. برای همین در طراحی، دو نسخه را در دو دامنهٔ جدا میگذاری و بعد مطمئن میشوی آن دو دامنه واقعاً مستقلاند: برق جدا، خنککنندهٔ جدا، حتی تیم جدا.The boundaries nest: a room fuse, a floor fuse, the building's main switch. A fault low down takes only that flat; a fault high up takes everyone. The subtle part is that a boundary only holds if the fault really stops there. If one electrician wired every flat in one week, the flats probably share a defect too, and the boundary is only on paper. That is why you put two copies in two separate domains and then check that the two are genuinely independent: separate power, separate cooling, even a separate team.
هر پله دامنهٔ بزرگتری است؛ خرابی در پلهٔ پایین کوچکتر مهار میشود، ولی هماهنگی بیشتری میخواهد.Each rung is a bigger domain: a lower rung contains failure more tightly, a higher one needs more coordination.
و بعدش، فنیAnd now, technically
دامنهٔ خرابی مرزِ مهار یک خرابی است و در عمل با واحدهای فیزیکی شمرده میشود: پروسه، ماشین، رک، مرکز داده، منطقهٔ دسترسپذیری و منطقه. هرچه دامنه کوچکتر، خرابیش کوچکتر، ولی هماهنگی گرانتر. قاعدهٔ اصلی این است که افزونگی فقط وقتی معنا دارد که نسخهها در دامنههای مختلف باشند؛ دو نسخه روی دو ماشین از یک رک، با یک سوئیچ از کار میافتند. دامنهها را باید با خرابی واقعی سنجید، نه با نقشه: برق، شبکه، خنککننده و مهمتر از همه نرمافزار و کانفیگ مشترک میتوانند دو دامنهٔ ظاهراً جدا را به هم بچسبانند. ظرفیت هم باید طوری باشد که با رفتن یک دامنه، بقیه بار را بردارند؛ وگرنه افزونگی روی کاغذ است. یک خرابی نرمافزاری که روی همهٔ نسخهها هست، از هر مرز فیزیکی رد میشود و تنها با انتشار تدریجی و امکان برگشت مهار میشود.A failure domain is the boundary that contains a fault, and in practice it is counted in physical units: a process, a machine, a rack, a data centre, an availability zone, a region. Smaller domains mean smaller failures but more coordination. The central rule is that redundancy only means something when the copies sit in different domains; two copies on two machines in one rack die with one switch. Domains must be tested with real faults rather than read off a diagram: power, network, cooling and, above all, shared software and config can glue two apparently separate domains together. Capacity must also survive losing a whole domain, or the redundancy is on paper. And a software fault present on every copy crosses every physical boundary; only gradual rollout and a way back contain it.
2+ domainsنسخهها باید در دو دامنهٔ واقعاً جدا باشند، نه دو ماشین از یک رکcopies belong in two genuinely separate domains, not two machines in one rack
N+1ظرفیت باید با رفتن یک دامنه هنوز جواب بدهدcapacity must still serve after one domain is gone
تلهٔ رایجThe usual trap
با «دو دیتاسنتر داریم» خیال راحت شدن، در حالی که هر دو از یک مسیر شبکه و یک کنسول کانفیگ تغذیه میشوند. دامنهٔ خرابی را باید با تزریق خرابی اندازه بگیری، نه با آدرسها.Relaxing because “we have two data centres”, when both are fed by one network path and one config console. A failure domain is measured by injecting faults, not by reading addresses.
اگر فردا خراب شود، اولین بار است که تمرینش میکنی؟If it breaks tomorrow, will that be your first rehearsal?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
هفتهٔ اول مدرسه زنگ میزنند و همه باید از پلهها پایین بروند؛ معلم میگوید این تمرین است. بچهها غر میزنند، ولی همان تمرین یک چیز را لو میدهد: درِ راهپله قفل است. تمرین خرابی هم همین است: خرابی را سرِ فرصت امتحان میکنی تا غافلگیری را در یک روز معمولی ببینی، نه در شب حادثه.In the first week of school a bell rings and everyone has to walk down the stairs; the teacher says it is a drill. The children grumble, but the drill gives one thing away: the stairwell door is locked. A failure drill is the same: you test the failure while it is cheap, so the surprise happens on an ordinary day, not on the night it is real.
تشبیه و تصویر ذهنیThe analogy
تمرین وقتی فایده دارد که چیزی را عوض کند. اگر بعد از هر تمرین فهرست کوتاهی از چیزهایی که خراب بود بنویسی و همانها را درست کنی، دفعهٔ بعد تمرین واقعاً یک آزمون است، نه نمایش. بهایش هم روشن است: آدمها وقت میگذارند، کار عادی میایستد و بعضیها ناراحت میشوند. برای همین تمرین را کوچک و مکرر میکنند، نه بزرگ و سالی یک بار. و تمرینِ از قبل اعلامشده فقط نیمهٔ کار است؛ نیمهٔ دیگر این است که آدمها بدانند ممکن است همین امروز باشد.A drill is worth it only if it changes something. If after each one you write a short list of what was broken and fix those things, the next drill is a real test rather than theatre. The cost is clear: people spend time, normal work stops, and some of them are annoyed. That is why drills stay small and repeated rather than huge and annual. And an announced drill is only half the work; the other half is people knowing it might come today.
تمرین وقتی کامل است که خرابی واقعاً تزریق شود و خروجیاش یک بلیت و یک عدد باشد.A drill is complete when the fault is really injected and the output is a ticket and a number.
و بعدش، فنیAnd now, technically
تمرین خرابی یک آزمایش کنترلشده است: یک فرضیه میسازی («اگر رهبر برق بیفتد، در چند ثانیه جانشین کار را بردارد؟»)، خرابی را واقعاً ایجاد میکنی، و زمان تشخیص، زمان جابهجایی و میزان دادهٔ از دسترفته را اندازه میگیری. سه چیز را از هم جدا کن: تمرین failover، تمرین بازیابی از پشتیبان (که بیشتر تیمها هرگز واقعاً انجامش ندادهاند)، و تمرین خودِ آدمها (چه کسی صفحه را برمیدارد). خروجی هر تمرین باید یا یک بلیت باشد یا یک تغییر در runbook؛ وگرنه فقط هیجان بود. محدوده را از قبل تعیین کن: کدام سرویس، چقدر ترافیک، و چه کسی میتواند متوقفش کند، چون تمرین بدطراحیشده خودش یک حادثه است. مهندسی آشوب همان تمرین است که خودکار و مداوم اجرا میشود.A failure drill is a controlled experiment: you state a hypothesis (“if the leader dies, how many seconds until a successor takes over?”), you actually cause the failure, and you measure detection time, failover time and data loss. Keep three things apart: failover drills, restore-from-backup drills (which most teams have never really done), and people drills (who opens the incident page). Every drill should end with either a ticket or a change to the runbook, otherwise it was excitement with no purchase. Define the blast radius up front: which service, how much traffic, and who may abort, because a badly scoped drill is itself an outage. Chaos engineering is the same drill, automated and running continuously.
MTTRتمرین، عدد واقعی ترمیم را میدهد نه عدد روی کاغذa drill gives the real recovery number, not the one on paper
restore ≠ backupپشتیبانِ بازیابینشده، پشتیبان نیستa backup you have never restored is not a backup
تلهٔ رایجThe usual trap
تمرین بدون اندازهگیری و بدون پیگیری. خرابی تزریق میشود، همه میبینند سیستم برگشت، و هیچ عددی ثبت نمیشود؛ ماه بعد همان غافلگیری سر جایش است. اگر خروجی تمرین یک بلیت و یک عدد نباشد، هزینهاش را دادهای و چیزی نخریدهای.Drilling without measuring or following up. The fault is injected, everyone sees the system come back, and no number is written down; next month the same surprise is still waiting. If a drill produces no ticket and no number, you paid the cost and bought nothing.
یک خبر، هزار مقصد؛ هزینهاش را کجا میدهی؟One event, a thousand destinations. Where do you pay for it?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
برای عروسی دویست کارت دعوت داری. یک راه این است که دویست پاکت بنویسی و به هر مهمان یکی برسانی؛ مهمان فقط پاکت خودش را باز میکند و کارش تمام است. راه دوم این است که یک اطلاعیه در روزنامه بدهی؛ تو یک بار کار میکنی، ولی هر مهمان باید روزنامه بخرد و آگهی را پیدا کند. fan-out همین انتخاب است: کار را یک بار برای همه انجام بدهی، یا هر بار برای هر کس.You have two hundred wedding invitations to deliver. One way is to write two hundred envelopes and hand each guest their own; the guest opens one envelope and is done. The other is a single notice in the newspaper: you work once, but every guest has to buy the paper and find the notice. Fan-out is that choice — do the work once for everyone, or every time for each one.
تشبیه و تصویر ذهنیThe analogy
هر دو راه هزینه دارند و فقط جایش عوض میشود. با کارتها تو دویست بار زحمت میکشی، ولی هر مهمان در دو ثانیه دعوتش را میبیند؛ با روزنامه تو یک بار زحمت میکشی، ولی هر مهمان باید برود و بگردد. اگر مهمانها را از قبل بشناسی کارت ارزانتر تمام میشود، چون میدانی چند پاکت لازم داری. حالا تصور کن یکی از مهمانها خودش مشهور است و پنج هزار نفر میخواهند دعوت او را ببینند: نوشتن پنج هزار پاکت برای یک نفر معنی ندارد، پس برای او اطلاعیه میدهی و بقیه کارت میگیرند. سیستمهای واقعی هم همین کار را میکنند: مسیر معمول را از قبل میسازند و برای حسابهای بزرگ مسیر را عوض میکنند.Both ways cost, and only the place changes. With cards you work two hundred times, but each guest sees the invitation in two seconds; with the newspaper you work once, but every guest has to go and look. If you know the guest list in advance, cards are cheaper, because you know how many envelopes you need. Now suppose one guest is famous and five thousand people want to see their invitation: writing five thousand envelopes for one person makes no sense, so you run a notice for them and hand cards to the rest. Real systems do the same — build the usual path in advance and flip the path for the big accounts.
یک پست، چند نسخهٔ از پیش ساخته: خواندن ارزان میشود و نوشتن گران.One post, several prebuilt copies: reads get cheap and writes get expensive.
و بعدش، فنیAnd now, technically
در سمت نوشتن، هر رویداد بلافاصله به N مقصد رونویسی میشود؛ نتیجه خواندنهای ساده است، چون تایملاین هر کاربر از قبل ساخته شده و فقط خوانده میشود. هزینهاش این است که هر نوشتن N بار انجام میشود، با N بزرگ، کند و شکننده میشود، و ذخیرهسازی هم N برابر میشود. در سمت خواندن، رویداد یک جا ذخیره میشود و هنگام خواندن از چند جا جمع میشود؛ نوشتن ارزان است، ولی هر خواندن باید N ردیف را بیاورد و مرتب کند. جایی که این انتخاب خراب میشود توزیع N است: وقتی N برای همه یکسان باشد خوب است، ولی یک حساب با صد هزار دنبالکننده با بقیه فرق دارد. راهحل صنعتی دورگه است: مسیر عادی از قبل ساخته میشود و برای حسابهای بزرگ موقع خواندن جمع میشود. پخش معمولاً نباید داخل همان درخواست انجام شود، بلکه با یک صف و بهصورت idempotent، تا تکرار تحویل، رکورد تکراری نسازد.On the write side each event is copied straight into N destinations; reads become simple because every timeline was built ahead of time. The cost is that each write happens N times, which gets slow and fragile as N grows, and storage grows N times. On the read side the event is stored once and gathered from several places at read time: writes are cheap, but every read must fetch and merge N rows. What breaks the choice is the distribution of N: a constant N is fine, but one account with a hundred thousand followers is not like the others. The industrial answer is a hybrid — precompute the normal path and gather at read time for the big accounts. And the spread usually should not happen inside the request: put it behind a queue and make it idempotent, so a redelivery does not create duplicate rows.
1 → Nهر رویداد N بار نوشته میشود و ذخیرهسازی هم N برابرeach event is written N times, and storage grows N times
p99 of Nزمان یک صفحه، کندترین تماس از N تماس استa page takes as long as the slowest of its N calls
~10kاز همین حدود دنبالکننده، پخش موقع نوشتن برای یک حساب گران میشودaround here, write-time fan-out for one account gets expensive
چرا یک کندی کوچک کل صفحه را میخواباندWhy one small pause sinks the page
وقتی یک صفحه صد سرویس را صدا میزند، زمانش برابر کندترین آنهاست، نه میانگینشان. اگر هر تماس یک درصد شانس کندی داشته باشد، احتمال اینکه دستکم یکی از صد تماس کند باشد حدود ۶۳ درصد است؛ یعنی صفحهای که تکتک سرویسهایش خوبند، برای بیشتر کاربران کند است. این همان tail latency amplification است و دلیل اینکه fan-out زیاد، حتی با سرویسهای سالم، تأخیر را بالا میبرد. دو راه کم کردنش: موازی کردن تماسها بهجای زنجیره کردنشان، و کم کردن N؛ هر تماسی که حذف میشود، یک شانس کندی را هم حذف میکند.When a page calls a hundred services, its time is the slowest of them, not the average. If each call has a one percent chance of being slow, the chance that at least one of a hundred is slow is about 63%: a page whose every service is fine is slow for most users. That is tail latency amplification, and it is why heavy fan-out raises latency even when every backend is healthy. Two ways to cut it: run the calls in parallel instead of in a chain, and reduce N — every call you remove removes one chance of a pause.
کجا باید انشعاب را قطع کنیWhere to cut the spread
سه جا وجود دارد که باید جلوی fan-out را بگیری. اول، حسابهای داغ: برای کسی با صد هزار دنبالکننده، نوشتن موقع انتشار یک عملیات سنگین است، پس یا سقف میگذاری یا مسیرش را عوض میکنی. دوم، عمق: اگر هر رکورد بهنوبهٔ خودش دوباره پخش شود، یک رویداد میتواند هزاران نوشتن بسازد؛ عمق را محدود کن. سوم، شکست: پخش نیمهکاره نباید داده را ناسازگار بگذارد، پس هر تکه باید جدا و قابل تکرار باشد و بشود فهمید کدام تکهها انجام شدهاند. اینجا یک شمارندهٔ سادهٔ پیشرفت و یک صف با تلاش دوبارهٔ کنترلشده، از هر طرح هوشمندانهای بیشتر نجات میدهد.Three places to stop a fan-out. Hot accounts: for someone with a hundred thousand followers, writing at post time is heavy work, so either cap it or flip the path. Depth: if each record fans out again in turn, one event can produce thousands of writes — bound the depth. Failure: a half-finished spread must not leave the data inconsistent, so each slice has to be separately retryable and you must be able to tell which slices landed. Here a plain progress counter and a queue with bounded retries save you more often than any clever scheme.
تلهٔ رایجThe usual trap
بدترین شکل fan-out، انجام دادنش داخل همان درخواست کاربر است: یک پست ثبت میشود و بعد صد هزار نوشتن دیگر هم باید تمام شوند تا پاسخ برگردد. کافی است یکی از آنها کند شود تا پست ثبت نشود؛ کاربر دوباره تلاش میکند و حالا دو نسخه داریم. پخش را از مسیر درخواست بیرون بگذار و idempotent کن، وگرنه هر تلاش دوباره یک ردیف تکراری به تایملاین اضافه میکند.The worst shape of fan-out is doing it inside the request: the post is saved and a hundred thousand more writes must finish before the reply goes out. One slow write and the post is never saved; the user retries and now there are two. Move the spread off the request path and make it idempotent, or every retry adds another row to the timeline.
این سرور زنده است، یا فقط نفس میکشد؟Is this server healthy, or merely breathing?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
توی مطب، منشی قبل از فرستادن بیمار، از پشت در میپرسد «آمادهای؟». اگر جواب نیاید، بیمار را به اتاق بعدی میفرستد. این پرسش نمیگوید دکتر چقدر خوب است، فقط میگوید همین حالا میشود فرستاد یا نه — و بررسی سلامت همان پرسش است، فقط خودکار و هر چند ثانیه یک بار.At the clinic, before sending a patient in, the receptionist asks through the door, “ready?”. If there is no answer, the patient goes to the next room. That question does not say how good the doctor is; it only says whether someone can be sent in right now — and a health check is the same question, asked automatically every few seconds.
تشبیه و تصویر ذهنیThe analogy
بررسی سلامت دو حالت افراطی دارد. اگر خیلی سطحی باشد، فقط میپرسد «پروسه بالاست؟» و پروسهای که در بنبست قفل شده هم جواب میدهد. اگر خیلی عمیق باشد، وابستگیهایش را هم امتحان میکند؛ حالا اگر دیتابیس کند شود، همهٔ نسخهها همزمان «بیمار» اعلام میشوند و توزیعکننده ترافیک را از همه برمیدارد، یعنی یک کندی به یک قطعی کامل تبدیل میشود. انتخاب معمول بین این دو، یک بررسی محلی و ارزان است: این نسخه میتواند درخواست بگیرد و به دیتابیس برسد، ولی خودش بار سنگین تولید نمیکند. بررسی باید مثل همان سؤال پشت در باشد: سریع، کوتاه، و بدون اینکه کل مطب را به هم بریزد.A health check has two extreme modes. Too shallow, and it only asks “is the process up?” — a process stuck in a deadlock answers yes. Too deep, and it tests its dependencies; now when the database slows down every instance is declared sick at once and the balancer pulls traffic from all of them, turning a slowdown into a full outage. The usual choice sits in between: a cheap local check saying this instance can accept a request and reach the database, without generating heavy load itself. The probe should be like that question through the door: quick, short, and not upsetting the whole clinic.
چند شکست پشتهم نسخه را از گردش خارج میکند؛ بازگشت هم آستانه و مهلت خودش را دارد.Several failures in a row take an instance out; coming back has its own threshold and delay.
و بعدش، فنیAnd now, technically
در عمل دو پرسش جدا وجود دارد. liveness میپرسد «این پروسه هنوز کار میکند یا باید ریاستارت شود؟» و readiness میپرسد «حالا میتواند ترافیک بگیرد؟». جواب اولی باید از داخل خود پروسه بیاید و به وابستگیها دست نزند، چون اگر دیتابیس کند شود و liveness هم شکست بخورد، ارکستریتور همهٔ نسخههای سالم را پشت سر هم ریاستارت میکند و خرابی بدتر میشود. جواب دومی میتواند به وابستگی نگاه کند، ولی باید محافظهکار باشد: چند شکست پشت سر هم، نه یکی؛ و یک دورهٔ مهلت قبل از بازگشت به گردش. خود بررسی باید ارزان و محدود باشد، وگرنه به بار تبدیل میشود؛ بررسیای که هر ثانیه اجرا شود و کوئری سنگین بزند، در روز حادثه اولین چیزی است که سیستم را میاندازد. یک نکتهٔ دیگر: بررسی باید از همان مسیری برود که کاربر میرود، نه از یک پورت جانبی که فقط میگوید پروسه زنده است.In practice there are two separate questions. Liveness asks “is this process still working, or should it be restarted?”, and readiness asks “may it take traffic right now?”. A liveness answer must come from inside the process and must not touch dependencies, because if the database slows and liveness fails too, the orchestrator restarts every healthy instance one after another and makes things worse. Readiness may look at dependencies but should be conservative: several failures in a row rather than one, and a grace period before returning to rotation. The probe itself must be cheap and bounded, or it becomes load; a check that runs every second and issues a heavy query is the first thing to take the system down on a bad day. One more thing: the probe should take the same path a user does, not a side port that only proves the process is alive.
5–10 sفاصلهٔ معمول بین دو بررسیa typical gap between two probes
2–3شکست پشت سر هم تا نسخه از گردش خارج شودconsecutive failures before an instance leaves rotation
تلهٔ رایجThe usual trap
وابسته کردن liveness به دیتابیس. نتیجهاش این است که یک کندی در دیتابیس همهٔ نسخهها را همزمان میکشد و آن کندی به قطعی کامل تبدیل میشود، در حالی که نسخهها سالم بودند و فقط باید صبر میکردند.Wiring liveness to the database. Then one slow query kills every instance at once and the slowdown becomes a full outage, even though the instances were healthy and only needed to wait.
چرا فیبر پهنتر، جواب را زودتر نمیرساند؟Why does a fatter cable not bring the answer sooner?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
با خویشاوندی که آن طرف دنیاست تماس تصویری میگیری. حرف میزنی و او نیم ثانیه بعد شروع میکند؛ بعد هر دو با هم حرف میزنیم و همدیگر را قطع میکنیم. آن نیم ثانیه با سریعتر کردن اینترنت خودت درست نمیشود، چون بخشی از آن صرف رفتن سیگنال در کابل و ماهواره میشود. latency همین است: فاصله، به واحد زمان.You video-call a relative on the other side of the world. You speak and they start half a second later; then you both talk at once and cut each other off. That half second does not go away with a faster connection at your end, because part of it is the signal travelling through cable and satellite. Latency is that: distance, measured in time.
تشبیه و تصویر ذهنیThe analogy
همان تماس سه بخش دارد و فقط یکیاش به سرعت اینترنت تو مربوط است. بخش اول رفتوبرگشت سیگنال است: هر هزار کیلومتر فیبر چند میلیثانیه و مسیرهای خیلی دور چند صد میلیثانیه. بخش دوم کاری است که سرور انجام میدهد. بخش سوم انتظار در صف است: اگر ده هزار تماس همزمان به یک سرور برسد، تماس تو پشت بقیه مینشیند و تأخیرش چند برابر میشود، در حالی که هیچ قطعهای خراب نیست. پهنای باند بیشتر فقط بخش دوم را بهتر میکند، آن هم نه همیشه؛ لولهٔ ضخیمتر آب بیشتری جابهجا میکند، ولی سرعت حرکت قطره را عوض نمیکند.The call has three parts and only one depends on how fast your connection is. First, the round trip of the signal: a few milliseconds per thousand kilometres of fibre, a few hundred for very distant routes. Second, the work the server does. Third, waiting in a queue: if ten thousand calls hit one server at once, yours waits behind the others and its delay multiplies, though nothing is broken. More bandwidth helps only the second part, and not always at that — a wider pipe carries more water, it does not move a drop any faster.
جایی که تأخیر یک درخواست در ثانیههای شلوغی خرج میشود: بیشترش صف است، نه کد.Where one request's delay goes at a busy second: most of it is the queue, not the code.
و بعدش، فنیAnd now, technically
تأخیر از چند تکه ساخته میشود و هر تکه واحد خودش را دارد: خواندن از حافظهٔ خود پروسه حدود صد نانوثانیه، یک خواندن از SSD حدود صد میکروثانیه، یک جستوجوی دیسک چند میلیثانیه، و یک رفتوبرگشت در همان دیتاسنتر حدود نیم میلیثانیه. بین دو قاره همین رفتوبرگشت به صد تا دویست میلیثانیه میرسد و هیچ مقدار پهنای باندی کوتاهش نمیکند، چون محدودیت سرعت نور در فیبر است. تأخیر یک عدد نیست، توزیع است: هر درخواست داستان خودش را دارد و دنبالهٔ کند همان چیزی است که کاربر حس میکند. یک رابطهٔ ساده همیشه برقرار است: تعداد درخواستهای همزمان تقریباً برابر است با نرخ ورود ضربدر زمان پاسخ؛ اگر نرخ دو برابر شود و ظرفیت نباشد، زمان پاسخ خودبهخود دو برابر میشود، بدون اینکه یک خط کد عوض شده باشد. به همین دلیل صف طولانیتر تأخیر را درمان نمیکند، فقط پشت آن را بلندتر میکند.Latency is built from pieces with different units: a read from the process's own memory is about a hundred nanoseconds, a read from an SSD about a hundred microseconds, a disk seek a few milliseconds, a round trip inside one datacenter about half a millisecond. Between continents that round trip is a hundred to two hundred milliseconds and no amount of bandwidth shortens it, because the limit is the speed of light in fibre. Latency is not a number, it is a distribution: every request has its own story, and the slow tail is what the user feels. One relation always holds: the number of concurrent requests is roughly the arrival rate times the response time; double the rate without more capacity and the response time doubles on its own, with no line of code changed. That is why a longer queue does not cure latency, it only makes the queue longer.
~0.5 msرفتوبرگشت در همان دیتاسنترa round trip inside the same datacenter
~100–200 msرفتوبرگشت بین دو قاره؛ پهنای باند این را کم نمیکندa round trip between continents; bandwidth cannot cut it
L = λWهمزمانی برابر نرخ ورود ضربدر زمان پاسخconcurrency equals arrival rate times response time
تأخیر و زمان پاسخ یکی نیستندLatency and response time are not the same
تأخیر معمولاً یعنی زمانی که خودِ مسیر و سرویس مصرف میکند؛ زمان پاسخ آن چیزی است که کاربر از لحظهٔ زدن دکمه تا دیدن نتیجه اندازه میگیرد و شامل صف، شبکه، رفتوبرگشت و حتی رندر شدن صفحه هم میشود. این تفاوت وقتی مهم میشود که بخواهی عددی را گزارش کنی: سرور میگوید بیست میلیثانیه، کاربر دو ثانیه منتظر مانده، و هر دو راست میگویند. برای همین اندازهگیری باید در نزدیکترین نقطه به کاربر باشد و همان مسیر واقعی را طی کند، وگرنه عددی جمع میکنی که هیچکس حسش نمیکند.Latency usually means the time the path and the service consume; response time is what the user measures from the tap to the result, and it includes the queue, the network, the round trip and even rendering. The difference matters when you report a number: the server says twenty milliseconds, the user waited two seconds, and both are telling the truth. So measurement belongs as close to the user as possible, on the real path, or you are collecting a number nobody experiences.
دنبالهٔ کند از کجا میآیدWhere the slow tail comes from
بیشتر درخواستها سریعاند؛ آن یکی درصد کند معمولاً از چند جای مشخص میآید: توقف GC، سرد بودن کش، صفحهفالت، فشردهسازی پسزمینه، همسایهٔ پرسروصدای همان ماشین، و تلاش دوبارهای که دو بار صف را طی میکند. هیچکدام در میانگین دیده نمیشوند و همه در دنباله دیده میشوند. کاری که واقعاً جواب میدهد، جدا کردن این دلایل است: برای هر endpoint توزیع را جدا اندازه بگیر، توقفهای طولانی را لاگ کن، و روی مسیر اصلی، بار را کم کن نه اینکه صف را بلندتر کنی.Most requests are fast; the slow one percent usually comes from a short list of places: a garbage collection pause, a cold cache, a page fault, background compaction, a noisy neighbour on the same machine, and a retry that crosses the queue twice. None of these show up in the average, and all of them show up in the tail. What actually helps is separating the causes: measure a distribution per endpoint, log the long pauses, and on the critical path shed load instead of growing the queue.
تأخیر در برابر گذردهیLatency versus throughput
تأخیرLatency
گذردهیThroughput
سؤالQuestion
هر درخواست چقدر طول میکشد؟how long does one request take?
در ثانیه چند تا؟how many per second?
واحدUnit
میلیثانیهmilliseconds
درخواست بر ثانیهrequests per second
با بار بیشترUnder more load
بدتر میشودit gets worse
تا سقف بالا میرود، بعد میافتدrises to a ceiling, then collapses
بهبودش باImproved by
کوتاه کردن مسیر و صفa shorter path and queue
موازی کردن و دستهکردنparallelism and batching
تلهٔ رایجThe usual trap
بهینهسازی برای گذردهی اغلب تأخیر را بدتر میکند: دستهکردن درخواستها و بافر بزرگتر تعداد کار در ثانیه را بالا میبرد، ولی هر درخواست بیشتر منتظر میماند. دام دوم، اندازهگیری در جای اشتباه است: سرور میگوید بیست میلیثانیه و کاربر دو ثانیه منتظر مانده، چون نیم ثانیهاش صرف شبکه و بقیه صرف صف شدن در کلاینت شده. عددی که اندازه میگیری، همان چیزی نیست که او حس میکند.Tuning for throughput often worsens latency: batching and bigger buffers raise the work per second while every request waits longer. The second trap is measuring in the wrong place: the server reports twenty milliseconds while the user waited two seconds, half of it network and the rest queued at the client. The number you measure is not the number they feel.
چه کسی تصمیم میگیرد این درخواست کدام ماشین برود؟Who decides which machine gets this request?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
در شعبهٔ بانک دستگاه نوبت شماره میدهد و کارمند راهنما میگوید «باجهٔ دو». تو صف نمیایستی، شماره میگیری و مینشینی؛ هر باجه که خالی شد نفر بعدی میرود. اگر راهنما نباشد و هر کس خودش یک باجه را انتخاب کند، پشت یکی صف میبندد و باجهٔ کنارش بیکار میماند. توزیعکنندهٔ بار همان راهنماست، با یک تفاوت: او هر چند ثانیه یک بار چشم باز میکند و باجهها را میشمارد.At the bank branch a machine issues a ticket and an usher says counter two. You do not queue; you take a number and sit down, and the next person goes to whichever counter frees up. Without the usher everyone picks a counter, one line grows and the counter next to it sits idle. The load balancer is that usher, with one difference: every few seconds he opens his eyes and counts the counters.
تشبیه و تصویر ذهنیThe analogy
همان شعبه دو تصمیم دارد که هر دو در سیستم هم هست. اول، یک صف مشترک یا یک صف برای هر باجه: با صف مشترک هیچ باجهای بیکار نمیماند ولی هر کس باید منتظر بماند تا نوبتش برسد؛ با صف جدا آدمها میتوانند باجهٔ کوتاهتر را انتخاب کنند، ولی یک باجهٔ کند کل صف خودش را زمینگیر میکند. دوم، اطلاعات راهنما از وضعیت عقب است: او فکر میکند باجهٔ سه باز است، در حالی که آن کارمند پنج دقیقه پیش رفته ناهار؛ پس یک نفر را به باجهٔ بسته میفرستد. و اگر خودِ راهنما از حال برود هیچکس جابهجا نمیشود، پس در سیستم جدی دو راهنما میگذاری و مطمئن میشوی هر دو یک فهرست دارند.That hall has two decisions, both present in a system. One shared queue or one per counter: with a shared queue no counter idles but everyone waits their turn; with separate queues people can pick the short one, but one slow counter sinks its whole line. And the usher's picture is behind reality: he thinks counter three is open while that clerk left for lunch five minutes ago, so he sends someone to a closed window. If the usher himself faints, nothing moves — which is why a serious system has two of them and makes sure they share the list.
درخواست به یک آدرس میرسد، توزیعکننده یکی از نسخههای سالم را انتخاب میکند، و بقیه آماده میمانند.The request arrives at one address, the balancer picks a healthy copy, and the rest stay ready.
و بعدش، فنیAnd now, technically
توزیعکنندهٔ بار معمولاً در دو لایه کار میکند. در لایهٔ چهار یعنی TCP فقط آدرس و پورت را میبیند و اتصال را به یک نسخه میفرستد؛ سریع و ساده است. در لایهٔ هفت درخواست HTTP را میفهمد، میتواند بر اساس مسیر یا هدر تصمیم بگیرد، TLS را تمام کند و هدر تازه اضافه کند. الگوریتمهای رایج سهاند: نوبتی، کمترین اتصال، و هش روی کلید که برای کش و نشست مفید است چون همان کلید همیشه به همان نسخه میرود. سلامت نسخهها با health check سنجیده میشود: یک درخواست دورهای و معمولاً چند شکست پشت سر هم تا نسخه از گردش خارج شود. نکتهٔ اصلی این است که توزیعکننده درخواست را پخش میکند، نه کار را؛ اگر یک درخواست دو ثانیه CPU بخواهد و بقیه دو میلیثانیه، توزیع نوبتی همان بار سنگین را هم به یک نسخهٔ بدبخت میدهد. خودش هم در مسیر همهٔ درخواستهاست، پس خودش نقطهٔ شکست است و باید جفت یا چندمسیره باشد.A load balancer usually works at one of two layers. At layer four, TCP, it sees only address and port and sends the connection to one copy: fast and simple. At layer seven it understands HTTP, so it can decide on path or header, terminate TLS and add headers. Three algorithms cover most cases: round robin, least connections, and a hash on a key, which helps caches and sessions because the same key always lands on the same copy. Health is checked with a periodic request and usually a few consecutive failures before a copy leaves rotation. The main point is that a load balancer spreads requests, not work: if one request needs two seconds of CPU and the rest need two milliseconds, round robin hands that heavy one to some unlucky copy too. And since it sits in the path of every request, it is itself a single point of failure and has to come as a pair or several paths.
L4 / L7دو لایهٔ کار: اتصال، یا خودِ درخواستtwo layers of work: the connection, or the request
5–10 sفاصلهٔ معمول یک health check از نسخهthe usual interval of a per-copy health check
2–3شکست پشت سر هم تا نسخه از گردش خارج شودconsecutive failures before a copy leaves rotation
سلامت را چطور میفهمیHow you know a copy is healthy
دو نوع بررسی هست و تفاوتشان مهم است. بررسی سطحی میگوید پروسه بالاست؛ ارزان است، ولی همان چیزی است که وقتی پایگاه داده رفته سبز میماند. بررسی عمیق وابستگیها را هم میسنجد؛ درستتر است، ولی اگر همهٔ نسخهها یک پایگاه دادهٔ مشترک را چک کنند، با یک لرزش کوچک در آن، همه با هم unhealthy میشوند و توزیعکننده جایی برای فرستادن ترافیک ندارد. راه میانه این است: بررسی سطحی برای تصمیم سریع، بررسی عمیقتر با آستانهٔ بالاتر، و یک بررسی غیرفعال که از خطاهای واقعی درخواستها یاد میگیرد. نسخهای که پنج بار پشت سر هم خطای ۵۰۲ داده، از هر بررسی ساختگیای گویاتر است.There are two kinds of check and the difference matters. A shallow check says the process is alive: cheap, and exactly what stays green when the database is gone. A deep check tests dependencies too: more truthful, but if every copy checks one shared database, a small wobble there marks them all unhealthy at once and the balancer has nowhere to send traffic. The middle path: a shallow check for fast decisions, a deeper one with a higher threshold, and a passive check that learns from real request errors. A copy that has returned 502 five times in a row is more informative than any synthetic probe.
نشست چسبنده و بهای آنSticky sessions and their price
بعضی سرویسها کاربر را به همان نسخه میچسبانند، چون نشست را در حافظهٔ همان نسخه نگه داشتهاند. این کار توزیع را نامتوازن میکند: یک نسخه میتواند پر شود در حالی که بقیه نفس میکشند، و با هر دیپلوی آن کاربران قطع میشوند. بدتر، حالت کاربر در جایی نگه داشته شده که موقتی است؛ با مرگ آن نسخه، کاربر بیرون میافتد و دوباره باید وارد شود. راه درست، بیرون کشیدن نشست است: یک سرویس مشترک یا یک توکن امضاشده که هر نسخه بتواند بخواند. آنوقت هر درخواست میتواند به هر نسخهای برود و توزیع دوباره متوازن میشود.Some services pin a user to one copy because the session lives in that copy's memory. That makes the balance uneven: one copy can fill while the rest breathe easy, and every deploy disconnects those users. Worse, user state now sits somewhere temporary; when that copy dies the user is thrown out and has to sign in again. The right move is to pull the session out — into a shared service or a signed token any copy can read. Then any request can go to any copy and the balance comes back.
تلهٔ رایجThe usual trap
اگر health check همهٔ نسخهها یک وابستگی مشترک را چک کند، با یک لرزش کوچک در آن پایگاه داده هر بیست نسخه همزمان unhealthy میشوند و توزیعکننده هیچجا برای فرستادن ترافیک ندارد؛ یک کندی کوتاه به قطعی کامل تبدیل میشود. خطای دوم، سنجیدن بار با تعداد اتصال است نه با کار: یک اتصال میتواند هزار درخواست سنگین باشد و اتصال دیگر هیچ.If every copy's health check tests one shared dependency, a small wobble there marks all twenty copies unhealthy at once and the balancer has nowhere to send traffic; a short slowdown becomes a full outage. The second error is measuring load by connection count instead of work: one connection can carry a thousand heavy requests and another none.
هزینهٔ ساختن را میدانی؛ هزینهٔ نگهداشتنش چقدر است؟You know what it cost to build. What does it cost to keep?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
کفش چرمیات را دو سال است میپوشی و کفاش تختش را عوض میکند؛ کفش تقریباً نو میشود. کفش ارزان چسبی را وقتی تختش سوراخ شود میاندازی دور. فرقشان همان نگهداشتپذیری است: میشود وصله کرد و ادامه داد، یا هر خرابی کوچک یعنی دور انداختن و از نو خریدن.You have worn the same leather shoes for two years; the cobbler replaces the soles and they are almost new. The cheap glued pair goes in the bin the moment the sole wears through. That is maintainability: can it be patched and kept going, or does every small failure mean throwing it away and buying again?
تشبیه و تصویر ذهنیThe analogy
نگهداشتپذیری سه تکه دارد و هر تکه صورتحساب جدایی دارد. بهرهبرداریپذیری: هر روز چقدر وقت آدمها را میگیرد تا سیستم را سرِ پا نگه دارند. سادگی: چقدر طول میکشد یک نفر تازه بفهمد چه خبر است. تحولپذیری: یک تغییر معمولی چقدر هزینه دارد. این هزینهها در روز اول دیده نمیشوند؛ در سال سوم دیده میشوند، وقتی سه نفر تماموقت فقط آپدیت و دیباگ میکنند. برای همین معیار خوب، نه زیبایی معماری، بلکه این است: آخرین باری که کسی چیزی را عوض کرد، چقدر طول کشید و چند نفر ترسیدند؟Maintainability has three parts and each one sends its own bill. Operability: how much of people's time it takes every day to keep the system standing. Simplicity: how long it takes a newcomer to understand what is going on. Evolvability: what an ordinary change costs. None of this shows up on launch day; it shows up in year three, when three people are full-time on upgrades and debugging. So the useful measure is not how elegant the architecture looks, but this: the last time someone changed something, how long did it take and how many people were afraid?
و بعدش، فنیAnd now, technically
کتاب نگهداشتپذیری را چتری روی سه چیز میبیند: بهرهبرداریپذیری، سادگی و تحولپذیری. نکتهٔ اصلی این است که بیشترِ هزینهٔ یک سیستم در نگه داشتنش خرج میشود، نه در ساختنش؛ و این هزینه در جلسهٔ بودجهٔ اول دیده نمیشود. چون عدد مستقیم ندارد، با نمایندهها اندازهگیری میشود: زمان تا اولین تغییر در یک بخش ناشناخته، مدت آشنایی یک نفر تازه، سهم کارهای تکراری دستی، و تعداد کارهایی که فقط یک نفر بلد است. همهٔ اینها با انتزاع و مرز بهتر میشوند، ولی انتزاع رایگان نیست: یک لایهٔ اضافه، یک جا برای پنهان شدن باگ و یک هزینهٔ فهمیدن است. تعادلش این است که انتزاع را جایی بگذاری که تغییر در آنجا زیاد است، نه جایی که فقط قشنگ به نظر میرسد. نتیجه این است که نگهداشتپذیری یک تصمیم روزمره است، نه یک بازبینی سالانه.The book treats maintainability as an umbrella over operability, simplicity and evolvability. The main point is that most of a system's cost is spent keeping it alive rather than building it, and that cost is invisible in the first budget meeting. Because there is no single number, it is measured through proxies: time to make the first change in an unfamiliar area, how long a newcomer takes to get oriented, the share of manual repetitive work, and how many tasks only one person knows. Abstractions and boundaries improve all of them, but abstraction is not free: an extra layer is a place for bugs to hide and a cost to understand. The balance is to put abstraction where change is frequent, not where it merely looks tidy. Which makes maintainability a daily decision, not an annual review.
سه تکهٔ نگهداشتپذیریThe three parts of maintainability
بهرهبرداریپذیریOperability
سادگیSimplicity
تحولپذیریEvolvability
پرسش اصلیThe question
هر روز چقدر کار دستی میخواهد؟how much daily manual work?
یک تازهوارد چقدر میفهمد؟what can a newcomer grasp?
یک تغییر معمولی چقدر طول میکشد؟how long does a usual change take?
نشانهٔ خوبA good sign
آدمها کم صدا زده میشوندpeople get paged rarely
نامها و مرزها روشناندnames and boundaries are clear
تغییر کوچک، انتشار کوچکsmall change, small release
اگر خراب شودWhen it goes wrong
هر حادثه یک ماجرای دستیevery incident is a manual saga
هر کس نسخهٔ ذهنی خودش را داردeveryone keeps a private model
هر تغییر یعنی پروژهٔ چندماههeach change becomes a project
تلهٔ رایجThe usual trap
سنجیدن نگهداشتپذیری با تعداد لایهها و الگوهای استفادهشده. معمارهایی که برای «آینده» پنج لایهٔ انتزاع میگذارند، غالباً تغییر را سختتر میکنند، چون هر تغییر باید از پنج جا رد شود. سادگی خودش بخشی از نگهداشتپذیری است، نه نقطهٔ مقابلش.Judging maintainability by how many layers and patterns you used. Architects who add five layers of abstraction “for the future” often make change harder, because every change has to pass through five places. Simplicity is part of maintainability, not its opposite.
سؤال تازهای پیش میآید؛ جوابش را از کجا میآوری؟A question you never planned for arrives. Where is the answer?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
قبض برق ماهانهات فقط یک عدد است. یک شب ساعت سه بیدار میشوی و میخواهی بدانی چرا مصرف بالا رفت؛ با کنتور هوشمندی که مصرف هر مدار را جدا و با زمان ثبت میکند میتوانی بپرسی «کولر یا یخچال؟» و جواب بگیری، ولی با آن یک عدد هیچ کاری نمیشود کرد. مشاهدهپذیری یعنی سیستم همان کنتور جزئی را داشته باشد، نه فقط صورتحساب آخر ماه.Your monthly electricity bill is a single number. One night you wake at three and want to know why consumption jumped; a smart meter that records each circuit separately, with timestamps, lets you ask “the air conditioner or the fridge?” and get an answer, while the single number gives you nothing. Observability means the system keeps that detailed meter, not just the end-of-month statement.
تشبیه و تصویر ذهنیThe analogy
تفاوت اصلی در سؤالهایی است که از قبل پیشبینی نکردهای. داشبورد خوب به سؤالهای دیروز جواب میدهد؛ مشاهدهپذیری به سؤال فردا هم جواب میدهد، چون دادهٔ خام و برچسبدار را نگه داشته، نه فقط چند عدد خلاصه. بهایش زیاد است: نگه داشتن همهچیز گران است، برچسبهای پرتنوع حافظه میخورند و بعضی دادهها را اصلاً نباید نگه داشت. برای همین در عمل نمونهبرداری و نگه داشت کوتاهمدت انتخاب میشود، و همانجا هم یک معاملهٔ دیگر هست: ارزانتر، ولی بعضی وقتها دقیقاً همان درخواست نحس نمونهبرداری نشده است.The real difference is in the questions you did not plan for. A good dashboard answers yesterday's questions; observability answers tomorrow's too, because it kept raw, labelled data instead of a few summary numbers. That costs a lot: keeping everything is expensive, high-cardinality labels eat memory, and some data should never be kept at all. So in practice you sample and keep a short window, and another trade-off sits right there: cheaper, but sometimes the one unlucky request was not sampled.
و بعدش، فنیAnd now, technically
مشاهدهپذیری از چند نوع سیگنال ساخته میشود: متریکهای عددی، لاگهای متنی و ردهای توزیعشده، و امروز بیشتر روی رویدادهای ساختیافته با ابعاد پرتنوع تأکید میشود. کلید کار این است که بتوانی از یک نشانهٔ بیرونی، مثل کندی صفحه، به علت درونی برسی، بدون اینکه کد تازه منتشر کنی؛ و این فقط وقتی ممکن است که هر درخواست یک شناسهٔ همبستگی داشته باشد که در همهٔ سرویسها و لاگها و اسپنها تکرار شود. هزینه از سه جا میآید: حجم ورود داده، تعداد مقادیر متمایز هر برچسب، و مدت نگه داشت. برچسبی مثل شناسهٔ کاربر تعداد مقادیر را از کنترل خارج میکند و حافظه و پول میبرد. در عمل بین نمونهبرداری و کامل بودن یکی را انتخاب میکنی، و خوب است بدانی کدام سؤالها را دیگر نمیتوانی بپرسی. تفاوت با مانیتورینگ هم همین است: مانیتورینگ سؤالهای از پیش نوشتهشده را جواب میدهد، مشاهدهپذیری باید سؤال تازه را هم جواب بدهد.Observability is built from a few kinds of signal: numeric metrics, text logs and distributed traces, with today's emphasis on structured events carrying rich dimensions. The key is being able to go from an external symptom, such as a slow page, to an internal cause without shipping new code, and that only works when a request carries a correlation id repeated across services, logs and spans. Cost comes from three places: ingest volume, the number of distinct values per label, and retention. A label like user id explodes the distinct count and eats memory and money. In practice you choose between sampling and completeness, and it helps to know which questions you can no longer ask. That is also the difference from monitoring: monitoring answers questions someone wrote in advance, observability has to answer a new one.
3 signalsمتریک، لاگ و رده؛ سه سیگنال رایجmetrics, logs and traces: the three usual signals
high cardinalityبرچسب پرتنوع، گرانترین بخش ذخیرهhigh-cardinality labels are the expensive part of storage
تلهٔ رایجThe usual trap
جمع کردن داده به امید اینکه «بعداً به کار میآید»، بدون تعریف هیچ سؤالی. نتیجه یک انبار لاگ گران است که هیچوقت کسی در آن جستوجو نکرده و روز حادثه هم کسی بلد نیست. مشاهدهپذیری با سؤال شروع میشود، نه با ابزار.Collecting data in the hope that it “will be useful later”, without naming a question. The result is an expensive log warehouse nobody has ever searched and nobody can use on the day of the incident. Observability starts from a question, not from a tool.
ساعت سه صبح، چه کسی میتواند این را راه بیندازد؟At three in the morning, who can get this running?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
نانوایی سر کوچه، هر شب موقع بستن، یک نفر باید یادش باشد شیر گاز اصلی را ببندد؛ هیچجا نوشته نشده. یک شب یادش میرود. نانوایی آنطرف خیابان یک کاغذ پشت در چسبانده: «گاز، آب، چراغ، در» — و همین تفاوت، بهرهبرداریپذیری است: اجرا کردن سیستم چقدر به حافظهٔ یک آدم وابسته است.Every night at closing, someone at the corner bakery has to remember to turn off the main gas valve; it is written nowhere. One night he forgets. The bakery across the street has a note taped to the door: “gas, water, lights, door” — and that difference is operability: how much running the system depends on one person's memory.
تشبیه و تصویر ذهنیThe analogy
بهرهبرداریپذیری یعنی سیستم را طوری بسازی که نگه داشتنش کار یک نفر عادی باشد، نه یک قهرمان. سه چیز بیشترین اثر را دارند: کارهای تکراری خودکار باشند، رفتار سیستم قابل پیشبینی باشد، و اطلاعات لازم برای عیبیابی در دسترس باشد. بهایش این است که اینها وقت مهندسی میبرند و هیچکدام در تبلیغ اولیه دیده نمیشوند. افراطش هم هست: خودکاری که هیچکس نفهمد چه میکند، خودش یک جعبهٔ سیاه است و روز حادثه جلوی تو را میگیرد. تعادل درست این است که خودکارسازی کارهای روزمره را بگیری و برای کارهای نادر، مسیر دستیِ مستند و آزمایششده نگه داری.Operability means building the system so that keeping it alive is an ordinary person's job, not a hero's. Three things matter most: routine tasks are automated, behaviour is predictable, and the information needed to diagnose a problem is at hand. The cost is that all of this takes engineering time and none of it shows up in the launch announcement. There is an excess too: automation nobody understands is a black box that blocks you on the bad day. The right balance is to automate the daily chores and keep a documented, rehearsed manual path for the rare ones.
و بعدش، فنیAnd now, technically
کتاب بهرهبرداریپذیری را با فهرست کارهای روزمره تعریف میکند: دیدن وضعیت درونی، خودکار کردن کارهای تکراری، وابسته نبودن به یک ماشین خاص، مستندسازی، و رفتار قابل پیشبینی با پیشفرضهای معقول. برخلاف مشاهدهپذیری که دربارهٔ فهمیدن است، بهرهبرداریپذیری دربارهٔ انجام دادن است: میشود این سیستم را با خیال راحت بالا آورد، جابهجا کرد و برگرداند یا نه. دو شاخص عملی دارد: سهم زمانی که صرف کار تکراری میشود، و تعداد مراحلی که فقط در ذهن یک نفر است. تیمهای کوچک معمولاً این کار را به خود تیم توسعه میدهند تا فاصلهٔ فهم و اقدام کوتاه بماند، ولی همین تصمیم هزینه دارد: آدمها بین ساختن و نگه داشتن تقسیم میشوند. هیچکدام از اینها رایگان نیست، ولی همهشان قابل اندازهگیریاند.The book defines operability by the everyday tasks: seeing the system's internal state, automating routine work, not depending on one particular machine, good documentation, and predictable behaviour with sensible defaults. Unlike observability, which is about understanding, operability is about doing: can this system be started, moved and rolled back safely? It has two practical indicators: the share of time spent on repetitive work, and the number of steps that live only in one person's head. Small teams usually hand this work to the development team so that the distance between understanding and acting stays short, but that choice has a price: people are split between building and keeping. None of it is free, and all of it can be measured.
3 a.m.معیار خوب: ساعت سه صبح، بدون زنگ زدن به کسی، بشود فهمید چه خبر استthe good test: at 3 a.m. you can tell what is wrong without calling anyone
0 manual stepsهدف برای کارهای روزمره: هیچ مرحلهٔ دستی نماندthe goal for routine work: no manual steps left
تلهٔ رایجThe usual trap
خودکار کردن چیزی که هنوز نمیفهمی. اسکریپتی که بیآنکه کسی بداند چه میکند هر شب دیتابیس را جابهجا میکند، بهرهبرداری را آسانتر نمیکند؛ فقط زمان حادثه را جلو میاندازد. اول مسیر دستی را بنویس و یک بار واقعاً اجرا کن، بعد خودکارش کن.Automating something you do not yet understand. A script that moves the database every night while nobody knows what it does does not make operations easier; it just brings the incident forward. Write the manual path down and run it once for real before you automate it.
میانگین خوب است؛ پس چرا مردم شکایت میکنند؟The average looks fine. Why are people complaining?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
سی روز پشت یک ایستگاه اتوبوس میایستی و مدت انتظار را یادداشت میکنی. بیشتر روزها پنج دقیقه است، چند روز ده دقیقه، و یک روز چهل دقیقه که به امتحان نرسیدی. اگر کسی میانگین بگیرد شاید هفت دقیقه دربیاید و بگوید خط خوب است؛ ولی آن یک روز همان چیزی است که برایت مانده. صدک ۹۹ همان روز است: یک درصد از انتظارها از آن بدتر بودهاند.For thirty days you wait at one bus stop and write down the wait. Most days it is five minutes, a few are ten, and one day it is forty and you miss the exam. Take the average and you may get seven minutes and conclude the line is fine; but that one day is what stayed with you. The 99th percentile is that day: one percent of waits were worse.
تشبیه و تصویر ذهنیThe analogy
صدک را با مرتب کردن همهٔ اندازهها میشود فهمید، نه با جمع کردنشان. فرض کن صد انتظار داری؛ اگر از کوتاه به بلند بچینی، صدک ۹۰ یعنی نود اندازه از صد اندازه کمتر از این بودهاند و صدک ۹۹ یعنی تنها یکی بدتر بوده. همین مرتب کردن یک چیز مهم را نشان میدهد: دنبالهٔ کند تصادفی نیست. همان آدمهایی در انتهای صف میایستند که بیشترین داده را دارند، قدیمیترین گوشی را، یا دورترین فاصله را؛ پس کندی دقیقاً به کسانی میخورد که بیشترین استفاده را میکنند. میانگین این را پنهان میکند، چون یک انتظار چهلدقیقهای را با سی انتظار پنجدقیقهای جمع میزند و یک عدد بیآزار تحویل میدهد.You understand a percentile by sorting the measurements, not by adding them. Suppose you have a hundred waits; sort them short to long and the 90th percentile means ninety of the hundred were shorter and the 99th means only one was worse. The sorting shows something important: the slow tail is not random. The same people end up at the back of the line — the ones with the most data, the oldest phone, the longest distance — so the slowness lands exactly on the heaviest users. The average hides this, because it adds one forty-minute wait to thirty five-minute waits and hands you a harmless number.
توزیع انتظار در یک ماه: میانگین حدود هفت دقیقه است، ولی یک درصد سفرها از چهل دقیقه گذشته.A month of waits: the average is about seven minutes, while one percent of trips went past forty.
و بعدش، فنیAnd now, technically
صدک از یک توزیع میآید، نه از یک عدد. برای حساب کردنش یا همهٔ نمونهها را نگه میداری که گران است، یا یک هیستوگرام با سطلهای ریز میسازی و صدک را از روی آن درمیآوری؛ کتابخانههایی مثل HdrHistogram همین کار را میکنند. یک محدودیت ریاضی مهم هست: صدکها را نمیشود میانگین گرفت. اگر دو نود داشته باشی که صدک ۹۹ هر کدام صد میلیثانیه است، صدک ۹۹ کل خوشه لزوماً صد میلیثانیه نیست، چون توزیعها با هم جمع نمیشوند؛ باید هیستوگرامها را ادغام کنی. همین مسئله در پنجرههای زمانی هم هست: صدک ۹۹ ساعتهای مختلف را میانگین نگیر. نکتهٔ عملی دیگر این است که برای صدک ۹۹.۹ به نمونهٔ زیادی نیاز داری؛ با هزار درخواست در دقیقه، صدک ۹۹.۹ فقط یک درخواست است و عدد پریدنی میشود.A percentile comes from a distribution, not from a single number. To compute it you either keep every sample, which is expensive, or build a histogram with fine buckets and read the percentile off it; libraries such as HdrHistogram do exactly that. There is one hard rule: you cannot average percentiles. If two nodes each report a 99th percentile of a hundred milliseconds, the cluster's 99th is not necessarily a hundred, because distributions do not add; you must merge the histograms. The same applies across time windows: do not average the p99 of different hours. And practically, a stable 99.9th needs a lot of samples; at a thousand requests a minute it is one request, and the number jumps around.
p50نیمی از نمونهها از این کمترند؛ همان میانهhalf the samples fall below it; the median
p99یک نمونه از هر صد تا از این کندتر استone sample in a hundred is slower than this
~10kنمونهٔ لازم در پنجره تا صدک ۹۹.۹ پریدنی نباشدsamples per window before a p99.9 stops jumping
میانگین چه چیزی را پنهان میکندWhat the mean hides
فرض کن ۹۹ درصد درخواستها پنجاه میلیثانیهاند و یک درصد دو ثانیه. میانگین حدود هفتاد میلیثانیه میشود؛ عددی آرام که دقیقاً هیچ کاربری تجربهاش نمیکند، چون هر کاربر یا پنجاه میلیثانیه دیده یا دو ثانیه. میانگین با یک دنبالهٔ بلند خراب میشود و همان دنباله، جایی است که کاربر عصبانی میشود و سفارش را رها میکند. برای همین هدفهای جدی روی دنباله نوشته میشوند: نه «میانگین زیر صد میلیثانیه»، بلکه «۹۹ درصد درخواستها زیر پانصد میلیثانیه». آن یک درصد هم تصادفی نیست؛ معمولاً همان کاربرهایی هستند که بیشترین داده را دارند.Suppose 99% of requests take fifty milliseconds and one percent take two seconds. The mean lands around seventy milliseconds: a calm number that no user actually experiences, because each user saw either fifty milliseconds or two seconds. A long tail drags the mean, and the tail is where a user gives up on the order. That is why serious targets are written on the tail: not a mean under a hundred milliseconds, but 99% of requests under five hundred. And that one percent is not random; it is usually the users with the most data.
صدک را روی چه چیزی حساب میکنیWhat you compute it over
صدک یک عدد است، ولی معنایش به سه انتخاب بستگی دارد: کدام نمونهها، کدام پنجره، و کدام نقطهٔ اندازهگیری. اگر درخواستهای خطادار را از تأخیر حذف کنی، عدد زیباتر میشود، چون خطا سریع برمیگردد؛ پس هر چه بیشتر خراب شوی، تأخیرت بهتر به نظر میرسد. اگر پنجره را کوتاه بگیری، عدد با هر اتفاق کوچک میپرد. اگر در لودبالانسر اندازه بگیری، کندی سمت کلاینت را نمیبینی. انتخاب درست، هم معمولاً سختتر است و هم کمجذابتر: پنجرهٔ چند دقیقهای، همهٔ درخواستها، و اندازهگیری روی مسیر واقعی کاربر، به تفکیک endpoint.A percentile is one number, but its meaning depends on three choices: which samples, which window, which measurement point. Drop failed requests from latency and the number improves, because errors return fast; the more broken you are, the better your latency looks. Shrink the window and the number jumps at every blip. Measure at the load balancer and you cannot see a slow client network. The honest choice is harder and less flattering: a window of several minutes, every request included, measured on the real user path, split by endpoint.
تلهٔ رایجThe usual trap
حذف درخواستهای خطادار از محاسبهٔ تأخیر، عدد را دروغین زیبا میکند: خطا سریع برمیگردد، پس هر چه بیشتر خراب شوی تأخیرت بهتر به نظر میرسد. خطای دوم، پنجرهٔ کوتاه است: در یک دقیقه با صد درخواست، صدک ۹۹ همان کندترین درخواست است و با یک اتفاق جابهجا میشود.Dropping failed requests from latency makes the number lie beautifully: errors return fast, so the more broken you are the better your latency looks. The second error is a short window: with a hundred requests in a minute, the p99 is simply the slowest request and jumps on a single event.
کاربر در تهران است؛ دادهاش کجا باید باشد؟The user is in Tehran. Where should their data live?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
کتابخانهٔ شهر سه شعبه دارد: مرکز، شمال و جنوب. کتابی که میخواهی در شعبهٔ مرکز هست و فردا میگیری؛ اگر فقط در شعبهٔ جنوب باشد، دو سه روز طول میکشد تا بین شعبهها جابهجا شود. منطقه هم همان مرز است: نسخهٔ داده را نزدیک کاربر میگذاری تا سریع باشد، و بابتش همگام نگه داشتن نسخهها را میپردازی.A city library has three branches: central, north and south. The book you want is in the central branch, so you pick it up tomorrow; if only the south branch has it, moving it between branches takes two or three days. A region is that boundary: you keep a copy of the data near the user so it is fast, and you pay for keeping the copies in step.
تشبیه و تصویر ذهنیThe analogy
یک منطقه سادهترین حالت است: همهچیز یکجا، همه نزدیک، هیچ ناهماهنگیای نیست. ولی کاربری که دو قاره دورتر است، هر درخواست را با تأخیر رفتوبرگشت میبیند، و یک فاجعهٔ بزرگ در آن منطقه همهچیز را میبرد. چند منطقه این دو مشکل را حل میکند و دو صورتحساب میآورد: نوشتن باید بین مناطق تکثیر شود، و نوشتن در دو جا یعنی یا تأخیر بیشتر یا تعارض. قانون هم تکهٔ سوم است: بعضی دادهها باید در خاک یک کشور بمانند، و این تصمیم فنی نیست. برای همین انتخاب منطقه معمولاً با سه پرسش شروع میشود: کاربر کجاست، فاجعه چقدر محتمل است، و قانون چه میگوید.One region is the simplest arrangement: everything together, everyone nearby, nothing to reconcile. But a user two continents away sees the round trip on every request, and one big disaster in that region takes everything with it. Several regions solve both problems and bring two bills: writes must be replicated between regions, and writing in two places means either more delay or conflicts. Law is a third piece: some data must stay inside one country's borders, and that decision is not technical. So the choice usually starts with three questions: where the users are, how likely a disaster is, and what the law says.
یک منطقه ساده و سریع است تا وقتی کاربر دور است یا فاجعهای بیاید؛ چند منطقه نزدیکی میخرد و تکثیر را میفروشد.One region is simple and fast until users are far or disaster hits; several regions buy locality and sell replication.
و بعدش، فنیAnd now, technically
در معماری ابری، منطقه مجموعهای از منطقههای دسترسپذیری در یک محدودهٔ جغرافیایی است، با تأخیر کم بین خودشان و تأخیر زیاد تا منطقههای دیگر. فاصله عدد را تعیین میکند: رفتوبرگشت درون یک قاره چند ده میلیثانیه است و بین دو قاره به صد تا دویست میلیثانیه میرسد، و این را هیچ پهنای باندی جبران نمیکند. سه الگوی رایج هست: نسخهٔ خواندنی در منطقهٔ دیگر (نوشتن یکجا، خواندن نزدیک)، فعال-غیرفعال (کل ترافیک در یک منطقه و جابهجایی در فاجعه)، و فعال-فعال (هر منطقه ترافیک خودش را میزند و نوشتنها بین مناطق تکثیر میشوند). الگوی سوم بیشترین نزدیکی به کاربر را میدهد و بیشترین هزینه را: تعارض نوشتن، تأخیر تکثیر و منطق حل اختلاف. یک نکتهٔ عملی هم هست: اقامت داده و قوانین محلی میتواند تصمیم را از دست تو بگیرد، پس قبل از انتخاب الگو آن را روشن کن.In cloud architecture a region is a set of availability zones in one geographic area, with low latency between them and high latency to other regions. Distance sets the number: a round trip within a continent is tens of milliseconds, between continents it is one to two hundred, and no amount of bandwidth fixes it. Three patterns are common: a read replica in another region (write in one place, read nearby), active-passive (all traffic in one region, switched over in a disaster), and active-active (each region serves its own traffic and writes replicate across). The third gives users the best locality and costs the most: write conflicts, replication lag and conflict-resolution logic. One practical note: data residency rules can take the decision out of your hands, so settle that before choosing a pattern.
≈ 100–200 msرفتوبرگشت بین دو قاره؛ پهنای باند کوتاهش نمیکندa round trip between continents; bandwidth does not shorten it
RPO > 0با تکثیر غیرهمزمان، فاجعه چند نوشتن آخر را میبردwith async replication a disaster takes the last few writes
تلهٔ رایجThe usual trap
چند منطقه را فقط برای تحمل خرابی انتخاب کردن و بعد فهمیدن که نوشتنها فقط در یک منطقه پذیرفته میشوند. آنوقت در فاجعه، منطقهٔ دوم همهچیز دارد جز نوشتنهای آخر. اگر جابهجایی میخواهی، مسیر نوشتن هم باید تمرین شده باشد.Choosing several regions for fault tolerance and then discovering that writes are accepted in only one. In a disaster the second region has everything except the last writes. If you want failover, the write path needs rehearsal too.
روشن میشود؛ ولی آیا کارش را درست انجام میدهد؟It switches on. But does it do the job right?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
ماشین لباسشویی خانه هر بار روشن میشود و برنامهاش را کامل میرود؛ از این نظر هیچ مشکلی ندارد. ولی هر چند هفته یک بار یک حوله را با لکهٔ سفید تحویل میدهد، و ماه پیش وسط شستوشو آب داد روی کفپوش. این ماشین در دسترس است ولی قابلاعتماد نیست: دسترسپذیری میپرسد «میشود استفاده کرد؟» و قابلیت اطمینان میپرسد «چند وقت یک بار درست کار میکند؟»The washing machine at home starts every time and runs its full cycle; on that count nothing is wrong with it. But every few weeks it hands back a towel with a white mark, and last month it leaked across the kitchen floor mid-wash. The machine is available, but it is not reliable. Availability asks whether you can use it; reliability asks how often it does the job right.
تشبیه و تصویر ذهنیThe analogy
سه جور چیز این ماشین را خراب میکند و هر سه در سیستم هم هستند. اول، قطعهٔ فرسوده: شلنگ پاره میشود، و این خرابیها معمولاً مستقل از هماند، پس میشود با قطعهٔ دوم جبرانشان کرد. دوم، طراحی: اگر نرمافزار ماشین باگی داشته باشد که در دمای بالای آب فعال شود، هر بار که آن شرایط پیش بیاید همان خرابی تکرار میشود؛ اینجا قطعهٔ دوم هیچ کمکی نمیکند، چون نسخهٔ دوم هم همان باگ را دارد. سوم، آدم: کسی فیلتر را درست نبسته و همه چیز به هم ریخته. در سیستمهای واقعی همین سهتا با هم میآیند و سختترینشان دوتای آخر است، چون همزمان روی همهٔ نسخهها اثر میگذارند.Three kinds of thing break that machine, and all three exist in a system. A worn part: a hose splits, and those failures are usually independent, so a second part can cover them. A design fault: if the machine's software has a bug that only triggers at high water temperature, the same failure repeats whenever those conditions return, and a second copy is no help because it has the same bug. And a person: someone refitted the filter wrong and everything went sideways. Real systems get all three at once, and the last two are the hard ones, because they hit every copy at the same time.
دو راه برای قابلاعتماد ماندن: جلوی خطا را بگیر، یا اثرش را بپوشان؛ هیچکدام تنها کافی نیست.Two ways to stay reliable: prevent the fault, or absorb it. Neither is enough alone.
و بعدش، فنیAnd now, technically
قابلیت اطمینان یعنی سیستم درست کار کند، حتی وقتی چیزی خراب میشود؛ و «درست» بخش سختش است، چون یک سیستم میتواند بالا باشد و جواب غلط بدهد. خرابی سختافزار تصادفی و نسبتاً مستقل است: با نرخ خرابی سالانهٔ حدود یکی دو درصد، ده هزار دیسک تقریباً هر دو روز یک خرابی میدهند، و برای همین نسخهٔ دوم کار میکند، چون احتمال خرابی همزمان دو نسخه پایین است. خرابی نرمافزار اما مستقل نیست: یک باگ روی همهٔ نسخهها هست و همزمان فعال میشود؛ اینجا افزونگی کمکی نمیکند و باید با تست، ایزوله کردن و کنترل دقیق انتشار مقابله کرد. خطای انسانی هم شایعترین منبع خرابی است: دستور اشتباه، تنظیم اشتباه، حذف اشتباه؛ و هیچ افزونگیای جلوی آن را نمیگیرد مگر همانقدر که محیط و ابزار جلویش را بگیرند. راه عملی، تمرین کردن خرابی است: خرابی تزریق کن، ببین چه میشود، و زمان ترمیم را اندازه بگیر؛ عددی که روی کاغذ نوشته شده با عددی که در تمرین درمیآید یکی نیست.Reliability means the system keeps doing its job correctly even when something breaks, and correctly is the hard half, because a system can be up and answering wrongly. Hardware faults are random and fairly independent: at an annual failure rate of one or two percent, ten thousand disks give a failure roughly every other day, which is why a second copy works — two copies failing at once is unlikely. Software faults are not independent: one bug sits on every copy and triggers at the same moment, so redundancy does not help; testing, isolation and disciplined rollout do. Human error is the most common source of all: a wrong command, a wrong setting, a wrong delete, and no amount of redundancy stops it beyond what the environment and the tooling forbid. The practical move is to rehearse failure: inject it, watch what happens, measure how long repair takes; the number on the slide and the number in the drill are never the same.
1–2%نرخ سالانهٔ خرابی دیسک در عملa disk's annual failure rate in practice
1 per 2 daysده هزار دیسک با این نرخ، تقریباً هر دو روز یک خرابیten thousand such disks give a failure about every two days
N−1ظرفیتی که با یک نسخهٔ خراب باید هنوز جواب بدهدthe capacity that must still answer with one copy down
خطا با شکست یکی نیستA fault is not a failure
خطا یعنی یک قطعه از رفتار درست بیرون رفته؛ شکست یعنی سیستم دیگر خدمت نمیدهد. فاصلهٔ این دو، همان کاری است که تحمل خطا انجام میدهد: خطا رخ میدهد و کسی نمیفهمد، چون نسخهٔ دوم جایش را میگیرد. همین پوشاندن، خودش خطر است: نسخهٔ دومی که ماهها خراب بوده و کسی نفهمیده، تا روزی که نسخهٔ اول هم برود، سالم به نظر میرسد. پس تحمل خطا بدون دیدن خطا، اعتماد کاذب میسازد؛ باید خطاها را بشماری و تمرین کنی، وگرنه فقط خرابی را به تعویق انداختهای.A fault is one component stepping outside correct behaviour; a failure is the system no longer serving. The gap between them is the work fault tolerance does: the fault happens and nobody notices, because a second copy takes over. That masking is itself a risk: a second copy that has been broken for months, unseen, looks healthy right up to the day the first one goes too. So tolerance without visibility builds false confidence; count the faults and rehearse them, or you have only postponed the failure.
سه منبع، سه درمانThree sources, three remedies
خرابی سختافزار را با افزونگی میپوشانند: دیسک دوم، سرور دوم، منطقهٔ دوم. این کار گران است و فقط برای خطاهای مستقل جواب میدهد. خرابی نرمافزار را با محدود کردن اثر میپوشانند: انتشار تدریجی، ایزوله کردن، خاموش کردن ویژگی با یک سوییچ، و تست روی دادهٔ واقعی. خطای انسانی را با سخت کردن مسیر اشتباه میپوشانند: محیط آزمایشی که شبیه تولید باشد، تأیید دو نفره برای کارهای خطرناک، بکاپی که واقعاً تست شده، و ابزاری که حذف را سخت کند. هیچکدام جای بقیه را نمیگیرد و هر سه با هم، تازه به یک سیستم قابلاعتماد میرسند.Hardware faults are absorbed with redundancy: a second disk, a second server, a second zone. That costs money and only works for independent faults. Software faults are absorbed by limiting their blast radius: gradual rollout, isolation, a switch that turns a feature off, and tests against real data. Human error is absorbed by making the wrong path hard: a staging environment that resembles production, a second pair of eyes on dangerous work, a backup that has actually been restored, and tooling that makes a delete difficult. None of these replaces the others, and only all three together get you a reliable system.
تلهٔ رایجThe usual trap
فرض استقلال، رایجترین خطاست: سه نسخه داری، ولی هر سه در یک رک، روی یک سوئیچ، با یک نسخهٔ کد؛ پس خرابی رک یا باگ آن نسخه هر سه را با هم میبرد. خطای دوم، تکیه بر افزونگی در برابر باگ است: اگر منطق اشتباه باشد، سه نسخه سه بار همان جواب غلط را میدهند، فقط با اطمینان بیشتر.Assuming independence is the most common mistake: you have three copies, but all three sit in one rack, on one switch, running one version of the code, so a rack failure or a bug takes all three. The second error is leaning on redundancy against bugs: if the logic is wrong, three copies return the same wrong answer three times, only more confidently.
از لحظهٔ درخواست تا جواب، چقدر طول میکشد؟From the request to the reply, how long does it actually take?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
ساعت نه به داروخانه میرسی و نوبت میگیری. ساعت نه و چهل اسمت را صدا میزنند و دارو را میدهند. آن چهل دقیقه زمان پاسخ است، ولی خودِ پیچیدن نسخه پنج دقیقه بیشتر نبود؛ بقیهاش انتظار بود — زمان پاسخ همین کل مسیر است، نه فقط وقتی که کسی مشغول کار توست.You reach the pharmacy at nine and take a ticket. At nine forty they call your name and hand over the medicine. Those forty minutes are the response time, but wrapping the prescription took five of them; the rest was waiting — response time is the whole trip, not just the part where someone is working on you.
تشبیه و تصویر ذهنیThe analogy
هر سیستمی یک زمان سرویس دارد: مدت واقعی انجام کار. زمان پاسخ اما از لحظهٔ رسیدن درخواست شروع میشود و انتظار در صف را هم شامل میشود. وقتی بار کم است این دو نزدیکاند و آدمها فکر میکنند یکی هستند. وقتی بار زیاد میشود صف بلند میشود و زمان پاسخ بدون اینکه یک خط کد عوض شود چند برابر میشود. برای همین «سرور ما درخواست را در پنج میلیثانیه جواب میدهد» جملهٔ بیمعنایی است اگر نگویی زیر چه باری. و میانگین هم گمراهکننده است، چون کاربری که پشت صف مانده میانگین را حس نمیکند؛ صدک نودونهم را حس میکند.Every system has a service time: the real duration of doing the work. Response time starts when the request arrives and includes the wait in the queue. Under light load the two are close and people conclude they are the same. Under heavy load the queue grows and response time multiplies without a line of code changing. That is why “our server answers in five milliseconds” means nothing unless you say under what load. Averages mislead too: the user stuck behind the queue does not feel the average, they feel the ninety-ninth percentile.
زمان پاسخ از لحظهٔ رسیدن تا برگشتن جواب است؛ زمان سرویس فقط وسط این مسیر است.Response time runs from arrival to the reply; service time is only the middle of that path.
و بعدش، فنیAnd now, technically
کتاب زمان پاسخ را چیزی میداند که کلاینت میبیند: زمان سرویس بهعلاوهٔ انتظار در صف، بهعلاوهٔ تأخیر شبکه در رفت و برگشت. تأخیر (latency) معمولاً به همان مدت منتظر ماندن اشاره دارد، یعنی بخشی از زمان پاسخ، نه کل آن؛ در گفتار روزمره این دو را یکی میگیرند و همین باعث بدخوانی متریکها میشود. جای اندازهگیری هم مهم است: عددی که سرور گزارش میکند صف را نمیبیند و اغلب از عددی که کاربر حس میکند خوشبینانهتر است. با نزدیک شدن بهرهبرداری به سقف، زمان پاسخ غیرخطی بالا میرود، چون صف سریعتر از ظرفیت رشد میکند. تلاش دوباره هم دو بار حساب میشود: هم زمان پاسخ را بالا میبرد، هم باری که سیستم را کند کرده بیشتر میکند. به همین دلیل اندازهگیری درست، نمونهبرداری از سمت کلاینت با صدکهاست، نه میانگینگیری از لاگ سرور.The book defines response time as what the client sees: service time plus queueing, plus the network trip out and back. Latency usually means the time spent waiting, a part of response time rather than the whole thing, and the everyday habit of using the two words together is a reliable source of bad metric reading. Where you measure matters: the number a server reports does not see the queue and is often rosier than what the user feels. As utilisation approaches the ceiling, response time rises non-linearly, because the queue grows faster than capacity does. Retries count twice: they raise response time and add the load that made the system slow. So the honest measurement samples at the client and reports percentiles, not an average of server logs.
queue + serviceزمان پاسخ همان انتظار بهعلاوهٔ سرویس است، بهعلاوهٔ شبکهresponse time is queue plus service, plus the network
L = λWهمزمانی برابر نرخ ورود ضربدر زمان پاسخ؛ صف از همین میآیدconcurrency equals arrival rate times response time; that is where the queue comes from
p99عددی که کاربر حس میکند، نه میانگینthe number a user feels, not the average
تلهٔ رایجThe usual trap
بهینه کردن میانگین. میانگین با یک اقلیت کند جابهجا نمیشود، ولی همان اقلیت است که تیکت پشتیبانی میسازد و کاربر را میراند. زمان پاسخ را با صدکها و در نقطهٔ کلاینت اندازه بگیر.Optimising the average. The average barely moves for a slow minority, and that minority writes the support tickets and leaves. Measure response time with percentiles, at the client.
چطور نسخهٔ تازه را بریزی و کسی متوجه نشود؟How do you ship the new version without anyone noticing?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
قفل در ورودی ساختمان بیستواحدی را عوض میکنی، ولی نمیتوانی یک شب همه را عوض کنی چون مردم نصفشب برمیگردند. پس هر روز یک در را عوض میکنی. در این میان دستهکلید سرایدار باید هم قفل قدیمی را باز کند هم نو، وگرنه از فردا صبح کسی نمیتواند وارد شود. ارتقای تدریجی همین است: نسخهها مدتی کنار هم زندگی میکنند، پس هر دو باید با هم کنار بیایند.You are changing the entrance locks of a twenty-unit building, and you cannot do them all in one night because people come home at midnight. So you change one door a day. In between, the caretaker's key ring has to open both the old lock and the new one, or nobody gets in tomorrow morning. A rolling upgrade is that: the versions live side by side for a while, so both have to get along.
تشبیه و تصویر ذهنیThe analogy
این کار سه شرط دارد. اول، سازگاری دوطرفه: کلید نو باید قفل قدیمی را هم باز کند، چون تا وقتی همهٔ درها عوض نشدهاند، بعضی آدمها فقط کلید نو دارند؛ و کلید قدیمی هم باید قفل نو را باز کند، چون ممکن است مجبور شوی برگردی عقب. دوم، ظرفیت: هر دری که در حال تعویض است عملاً بسته است، پس ساختمان باید با یک در کمتر هم کار کند. سوم، نظم: اگر سرایدار یک روز سه در را عوض کند و همان روز معلوم شود کلیدها اشتباه بریده شدهاند، سه خانواده بیرون ماندهاند؛ برای همین یکییکی و با فاصله عوض میکنی و بعد از هر در یک بار امتحان میکنی.The job has three conditions. Two-way compatibility: the new key must open the old lock, because until every door is changed some people carry only the new key; and the old key must open the new lock, because you may have to go back. Capacity: a door being changed is effectively closed, so the building has to work with one fewer door. And discipline: if the caretaker changes three doors in a day and the keys turn out to be cut wrong, three families are locked out; so you go one at a time, with a gap, and test after each door.
در تمام مدت ارتقا نسخهٔ قدیم و نو با هم بالا هستند؛ سازگاری، شرط همین بازه است.Throughout the rollout old and new run side by side; compatibility is the price of that window.
و بعدش، فنیAnd now, technically
ارتقای تدریجی یعنی یک نود را از گردش بیرون بیاوری، نسخهاش را عوض کنی، سالم بودنش را ببینی و بعد سراغ بعدی بروی؛ تا وقتی نودها یکییکی عوض میشوند بقیه جواب میدهند. برای این کار به ظرفیت اضافه نیاز داری: با یکی دو نسخهٔ کمتر هم باید بار را بکشی، وگرنه هر نود که بیرون میرود بقیه به سقف میخورند. شرط دوم سازگاری است: در تمام مدت ارتقا نسخهٔ قدیم و نو همزمان بالا هستند، با هم حرف میزنند و روی یک داده کار میکنند. اگر نسخهٔ نو فیلدی اضافه کند، نسخهٔ قدیم باید بتواند نادیدهاش بگیرد؛ اگر معنای فیلدی عوض شود، نسخهٔ قدیم باید همچنان درست کار کند، چون ممکن است مجبور شوی برگردی. و اگر کد نو دادهای با فرمت تازه بنویسد که کد قدیم نمیفهمد، دیگر rollback نداری، حتی اگر تصویر قدیمی را داشته باشی.A rolling upgrade takes one node out of rotation, replaces its version, checks that it is healthy, then moves to the next; while the nodes change one by one the rest keep answering. That needs spare capacity: the cluster must carry the load with one or two copies fewer, or each removal pushes the rest to the ceiling. The second condition is compatibility: for the whole rollout the old and new versions run at once, talk to each other and work on the same data. If the new version adds a field, the old one must ignore it; if it changes a field's meaning, the old one must still behave correctly, because you may have to go back. And if the new code writes a format the old code cannot read, you no longer have a rollback, even with the old image on disk.
1 nodeدر هر گام فقط یک نسخه از گردش خارج میشودone copy leaves rotation per step
N−1ظرفیتی که باید با یک نود کمتر هم جواب بدهدcapacity that must hold with one node fewer
2 versionsدر تمام مدت ارتقا، همزمان زنده و در حال گفتوگوalive and talking to each other the whole time
0 downtimeاگر سازگاری و ظرفیت از قبل تأمین شده باشدif compatibility and capacity were arranged first
ترتیب انتشار از خود انتشار مهمتر استThe order matters more than the rollout
تغییر داده سه گام دارد و ترتیبشان قابل جابهجایی نیست. گام اول، باز کردن: فیلد یا جدول تازه را اضافه کن، بدون اینکه کسی از آن استفاده کند؛ نسخهٔ قدیم آن را نمیبیند و نسخهٔ نو میتواند بنویسدش. گام دوم، پر کردن و دوخواندن: کد نو هر دو جا را پر کند و در خواندن، اول تازه را ببیند و اگر نبود قدیمی را. گام سوم، برچیدن: وقتی مطمئن شدی هیچ نسخهٔ قدیمی نمانده، فیلد قدیمی را حذف کن. هر کسی که گام اول و دوم را با هم انجام دهد، دقیقاً همان بازهای را میسازد که نسخهٔ قدیم روی دادهٔ ناشناخته میافتد و کرش میکند یا داده را صفر مینویسد.A data change has three steps and the order cannot be shuffled. Expand: add the new field or table without anyone using it; old code does not see it and new code can write it. Fill and dual-read: new code writes both places and, when reading, prefers the new one and falls back to the old. Contract: once no old version remains, delete the old field. Anyone who does expand and fill in one deploy creates exactly the window where old code meets data it does not understand, and either crashes or writes a zero over it.
ارتقای کند، یک ریسک تازه استA slow rollout is its own risk
ارتقای تدریجی از قطعی جلوگیری میکند، ولی بازهای میسازد که دو نسخه با هم کار میکنند و باگهای سازگاری فقط در همان بازه دیده میشوند؛ ممکن است ساعتها طول بکشد و هیچ تستی آن حالت را ندیده باشد. بدتر، اگر متریکها را نگاه نکنی، نسخهٔ بد هم آرامآرام به همه میرسد، فقط دیرتر. برای همین ارتقا باید همراه باشد با یک نسخهٔ کوچک که اول با ترافیک واقعی امتحان میشود، یک بازهٔ انتظار که در آن عددها بررسی شوند، و یک راه برگشت که واقعاً تمرین شده باشد. بدون این سه، «تدریجی» فقط یعنی خرابی را آهستهتر پخش میکنی.A rolling upgrade prevents an outage, but it creates a window where two versions cooperate and compatibility bugs appear only in that window; it can last hours, and no test has seen that state. Worse, if you do not watch the metrics, a bad version still reaches everyone, only later. So the rollout should come with a small first batch under real traffic, a wait long enough to read the numbers, and a way back that has actually been rehearsed. Without those three, gradual only means you spread the breakage more slowly.
تلهٔ رایجThe usual trap
رایجترین خطا، ریختن کد و تغییر ساختار داده با هم است: لحظهای که نسخهٔ قدیم روی دادهٔ تازه میافتد یا کرش میکند یا فیلد را صفر مینویسد، و چون ارتقا تدریجی است این حالت چند ساعت طول میکشد. خطای دوم، فرض کردن این است که rollback همیشه ممکن است؛ اگر نسخهٔ نو داده را با فرمت تازه نوشته باشد و نسخهٔ قدیم آن را نفهمد، برگشتن به عقب یعنی خرابی داده، نه نجات.The most common error is shipping the code and the schema change together: the moment old code meets new data it either crashes or writes a zero over the field, and because the rollout is gradual that state lasts for hours. The second error is assuming rollback is always available; if the new version wrote a format the old one cannot read, going back means corrupting data, not rescuing it.
«مقیاسپذیر» یعنی چه، دقیقاً؟What does “it scales” actually promise?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
عصر جمعه توی صف سوپرمارکت ایستادهای و صف تا ته راهرو رفته. مدیر دو راه دارد: صندوقدار را به دستگاه تندتر مجهز کند، یا صندوق دوم را باز کند و یک آدم دوم بیاورد. هیچکدام «بهتر» نیست تا وقتی نپرسی صف چقدر بلند میشود؛ مقیاسپذیری هم همین سؤال است، نه یک برچسب روی سیستم.It is Friday evening and you are in the supermarket queue, which now reaches the end of the aisle. The manager has two choices: give the cashier a faster scanner, or open a second till and bring in a second person. Neither is better until you ask how long the queue will get; scalability is that question, not a label on the box.
تشبیه و تصویر ذهنیThe analogy
صندوق دوم فقط با آوردن یک صندوقدار باز نمیشود؛ باید فروشگاه جای کافی داشته باشد، صف بین دو صندوق تقسیم شود، و کسی باشد که وقتی یکی از صندوقدارها رفت جای او را پر کند. اگر همهٔ مشتریها فقط بلد باشند از یک صندوقدار خرید کنند، صندوق دوم هیچ کمکی نمیکند. صندوق سوم و چهارم هم همینطور: هر صندوق اضافه، کار هماهنگی و هزینهٔ خودش را میآورد و سودش کمتر از خط است. برای همین مدیر خوب اول میپرسد گلوگاه کجاست، بعد تصمیم میگیرد صندوق باز کند یا صندوقدار را سریعتر کند.The second till does not open just because you hired someone: the shop needs the floor space, the queue has to be split between them, and somebody has to fill in when one cashier goes home. If every customer only knows how to buy from one till, the second one helps nobody. The same holds for the third and the fourth: each extra till brings its own coordination work and cost, and pays back less than the last. That is why a good manager asks where the bottleneck is before deciding to open a till or speed up the cashier.
دو راه بزرگکردن: ماشین قویتر با سقف نزدیک، یا ماشینهای بیشتر با هزینهٔ هماهنگی.Two ways to grow: a bigger machine with a nearer ceiling, or more machines with a coordination bill.
و بعدش، فنیAnd now, technically
مقیاسپذیری ویژگی یک سیستم بهتنهایی نیست؛ ویژگی سیستم در کنار یک پارامتر بار است. باید بگویی بار چطور زیاد میشود (درخواست بر ثانیه، نسبت خواندن به نوشتن، تعداد کاربر همزمان، اندازهٔ داده) و با چه معیاری میسنجی (گذردهی، تأخیر در صدک بالا، هزینهٔ هر درخواست، دسترسپذیری). بعد منحنی را میکشی: بار را زیاد میکنی و میبینی کدام معیار کجا میشکند. دو راه اصلی وجود دارد. scale up یعنی ماشین قویتر: ساده است، ولی سقف دارد و قیمتش خطی بالا نمیرود. scale out یعنی ماشین بیشتر: سقف را برمیدارد، ولی هر درخواست مسیر شبکه و هماهنگی بیشتری طی میکند و حالت مشترک بین ماشینها به گلوگاه تازه تبدیل میشود. در عمل هر دو را با هم میکنی: یک ماشین بزرگ برای بخش حالتمند و چند ماشین کوچک برای بخش بیحالت.Scalability is not a property of a system on its own; it is a property of the system together with a load parameter. You have to say how the load grows (requests per second, read-to-write ratio, concurrent users, data size) and which metric you are watching (throughput, high-percentile latency, cost per request, availability). Then you draw the curve: add load and see where a metric breaks. There are two main moves. Scale up means a stronger machine: simple, but it has a ceiling and its price does not rise linearly. Scale out means more machines: the ceiling goes away, but every request takes more network hops and more coordination, and the shared state between machines becomes the new bottleneck. In practice you do both: one large machine for the stateful part, many small ones for the stateless part.
10×بار را ده برابر کن و منحنی را تا آنجا بکش، نه تا دو برابرpush the load to ten times and draw the curve that far, not to twice
p99مقیاسپذیری را با صدک بالا بسنج، نه با میانگینjudge scaling at the high percentile, not at the mean
N+1با هر گره اضافه، کار هماهنگی هم اضافه میشود، نه فقط ظرفیتeach extra node adds coordination work, not only capacity
جملهٔ «مقیاسپذیر است» چه چیزی کم دارد؟What the sentence “it scales” leaves out
یک سیستم میتواند در خواندن مقیاسپذیر باشد و در نوشتن نه؛ در ده برابر شدن ترافیک دوام بیاورد و در ده برابر شدن حجم داده نه. تا وقتی پارامتر بار و معیار عملکرد را نگویی، «مقیاسپذیر» یک صفت تبلیغاتی است، نه یک ویژگی فنی. تیمها معمولاً یک عدد درخشان از یک آزمون بار را در دفترچهٔ فروش میگذارند و همان را جای منحنی جا میزنند. کاری که واقعاً جواب میدهد این است که بنویسی «با ده برابر شدن نوشتنها، تأخیر صدک ۹۹ حداکثر دو برابر شود» و بعد همان را اندازه بگیری.A system can scale for reads and not for writes, hold up when traffic grows tenfold and not when the data grows tenfold. Until you name the load parameter and the performance metric, “scalable” is a marketing adjective, not a technical property. Teams usually take one impressive number from one load test, put it in the sales deck, and treat it as the curve. What actually works is writing down “when writes grow tenfold, p99 latency at most doubles” and then measuring that.
کجای منحنی خم میشودWhere the curve bends
اگر بار را پلهپله زیاد کنی، گذردهی اول بالا میرود، بعد صاف میشود، و همان نزدیکی تأخیر از جا میکند. به آن نقطه زانو میگویند. زیر زانو، ماشینهای اضافه واقعاً کمک میکنند؛ بالای زانو، اضافهکردن بار فقط صف را بلندتر میکند و پاسخها دیرتر میرسند. خیلی از تیمها عدد گذردهی را از بالای زانو گزارش میکنند، چون بزرگتر به نظر میرسد، و بعد در تولید تعجب میکنند که چرا با نصف آن بار تأخیر منفجر میشود.Add load in steps and throughput first climbs, then flattens, and right about there latency departs. That point is the knee. Below the knee, extra machines genuinely help; above it, more load only makes the queue longer and answers arrive later. Plenty of teams report the throughput number from above the knee because it looks bigger, then are surprised in production when latency explodes at half that load.
تلهٔ رایجThe usual trap
یک لایه را مقیاسپذیر کردن و لایهٔ دیگر را جا گذاشتن. لایهٔ وب را سه برابر میکنی، عدد درخواست بر ثانیه بالا میرود، و بعد میبینی همهٔ نوشتنها به همان یک دیتابیس اصلی میرود و تأخیر بدتر شده. مقیاسپذیری یک سیستم، اندازهٔ تنگترین لایهٔ آن است.Scaling one layer and calling it scaled. You triple the web tier, the request rate goes up, and then you notice every write still lands on the same primary database and latency has got worse. A system scales only as far as its tightest layer.
۹۹.۹٪ را امضا کردی؛ آن یک دهم چه معنایی دارد؟You signed for 99.9%. What does that last tenth mean?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
مدیر ساختمان با شرکت آسانسور قرارداد میبندد: اگر آسانسور خراب شد، تا ۲۴ ساعت درستش میکنند وگرنه جریمه میدهند. سرایدار برای خودش هدف چهار ساعت گذاشته تا آن ۲۴ ساعت هیچوقت لمس نشود. آن قرارداد همان SLA است؛ چهار ساعتِ سرایدار، هدف داخلیای است که برای رسیدن به آن ساخته شده.The building manager signs a contract with the lift company: if the lift breaks, they fix it within 24 hours or pay a penalty. The caretaker privately aims for four hours so that the 24 never gets touched. The contract is the SLA; the caretaker's four hours is the internal target built to keep it.
تشبیه و تصویر ذهنیThe analogy
قرارداد یک بند دارد و هزار تفسیر. «تا ۲۴ ساعت» از کِی شمرده میشود، از لحظهٔ تماس یا از لحظهٔ رسیدن تعمیرکار؟ اگر قطعهٔ یدکی نبود تقصیر کیست؟ اگر برق ساختمان قطع بود و آسانسور سالم بود، جزو قرارداد است یا نه؟ اینها جزئیات کاغذبازی نیستند؛ همانجا معلوم میشود قرارداد یک تعهد است یا یک تزئین. شرکت آسانسور هم میداند جریمهٔ یک روز خرابی از دستدادن ساختمانهای بعدی ارزانتر است، پس عملاً سختتر از قرارداد کار میکند.The contract has one clause and a thousand readings. When does the 24 hours start, at the call or when the technician arrives? If the spare part was unavailable, whose fault is that? If the building's power was cut and the lift was fine, does that count? These are not paperwork details; they are where the contract shows whether it is a commitment or decoration. The lift company also knows a one-day penalty is cheaper than losing the next three buildings, so in practice it works harder than the contract says.
از چیزی که اندازه میگیری تا چیزی که امضا میکنی: هر پله یک قدم از مهندسی دورتر و یک قدم به قرارداد نزدیکتر.From what you measure to what you sign: each rung is one step away from engineering and one toward a contract.
و بعدش، فنیAnd now, technically
SLA توافقی است با مشتری یا واحد کسبوکار که سطح خدمت را تعریف میکند و برای نقض آن جبران مشخصی دارد: اعتبار خدمات، جریمه، یا حق فسخ. یک SLA قابل اجرا سه چیز لازم دارد: تعریف دقیق شاخص (چند درصد از درخواستها موفق باشند و از کدام نقطه اندازهگیری شود)، پنجرهٔ اندازهگیری (ماه تقویمی یا پنجرهٔ غلتان)، و استثناها (تعمیرات برنامهریزیشده، خرابی سرویسهای بالادستی، خطای خود مشتری). عرف رایج، دسترسپذیری ماهانه است: ۹۹.۹٪ یعنی حدود ۴۳ دقیقه خرابی در ماه و ۹۹.۹۹٪ یعنی حدود چهار دقیقه. مشکل این است که این عدد خرابی کامل را میسنجد نه کندی را؛ سرویسی میتواند SLA را رد نکند و در همان حال برای کاربر غیرقابل استفاده باشد. برای همین SLA را کف قانونی بدان، نه سقف کیفیت.An SLA is an agreement with a customer or a business unit that defines a service level and attaches a concrete remedy to breaking it: service credits, a penalty, or a right to walk away. A workable SLA needs three things: an exact metric (what share of requests must succeed, measured from where), a measurement window (calendar month or rolling), and exclusions (planned maintenance, upstream dependency failures, the customer's own errors). The usual shorthand is monthly availability: 99.9% is about 43 minutes of downtime a month, 99.99% about four minutes. The problem is that this number measures full outages, not slowness; a service can stay inside its SLA while being unusable for a user. Treat the SLA as the legal floor, not the quality ceiling.
99.9%حدود ۴۳ دقیقه خرابی در یک ماه تقویمیabout 43 minutes of downtime in a calendar month
99.99%حدود چهار دقیقه در ماه؛ هر ۹ اضافه هزینه را چند برابر میکندabout four minutes a month; each extra nine multiplies the cost
0.999^10 ≈ 99%ده وابستگی ۹۹.۹٪ روی هم، زنجیره را به ۹۹٪ میرساندten dependencies at 99.9% put the chain near 99%
۹۹.۹٪ آنقدر که به نظر میرسد بزرگ نیست99.9% is not as big as it sounds
یک ماه تقویمی حدود ۴۳ هزار دقیقه است؛ ۹۹.۹٪ یعنی میتوانی ۴۳ دقیقه از آن را از دست بدهی. وقتی این را بین استقرارها و مهاجرتها تقسیم کنی، میبینی بودجه کوچک است: بیست استقرار دو دقیقهای بودجه را تمام میکند. بدتر اینکه SLA روی زنجیره ضرب میشود: اگر یک درخواست به ده سرویس وابسته باشد که هر کدام ۹۹.۹٪ هستند، احتمال موفقیت کل تقریباً ۹۹٪ میشود، نه ۹۹.۹٪.A calendar month is about 43,000 minutes; 99.9% means you may lose 43 of them. Divide that across deploys and migrations and the budget looks small: twenty two-minute deploys exhaust it. Worse, an SLA multiplies along the chain: if one request depends on ten services at 99.9% each, the chance the whole thing succeeds is roughly 99%, not 99.9%.
چیزهایی که در قرارداد نوشته نمیشوندWhat the contract does not say
SLA معمولاً از خرابی کامل حرف میزند و از کندی، از دستدادن داده و افت جزئی حرف نمیزند. مشتری هم تجربهٔ خودش را از سمت خودش میسنجد: مرورگر، شبکهٔ محل، و انتظارش. اگر تو در سمت سرور بشماری، ممکن است همهچیز سبز باشد و او تایماوت ببیند. قبل از امضا بنویس شاخص از کجا اندازهگیری میشود، چه کسی اندازه میگیرد، و برای هر نوع خرابی چه اتفاقی میافتد.An SLA usually talks about full outages and stays quiet about slowness, data loss and partial degradation. The customer measures their own experience from their own side: their browser, their office network, their expectation. If you count on the server, everything can be green while they see timeouts. Before signing, write down where the metric is measured, who measures it, and what happens for each kind of failure.
تلهٔ رایجThe usual trap
SLA را هدف مهندسی گرفتن. تیم همهچیز را حول عددی میچیند که در قرارداد آمده، و چون عدد سخاوتمندانه است کندی و افت جزئی دیده نمیشود تا روزی که مشتریها یکییکی بروند. SLA کف قانونی است؛ جایی که تیم باید کار کند معمولاً کمی بالاتر از آن است.Treating the SLA as the engineering target. The team builds around the contract number, and because that number is generous, slowness and partial degradation go unseen until customers start leaving one by one. The SLA is the legal floor; where the team should live is a notch above it.
«خوب کار میکند» یعنی چه عددی؟“It works well” — which number exactly?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
چند بار از یک فروشگاه اینترنتی خرید کردهای و حالا کسی میپرسد «قابل اعتماد است؟». جوابت یک عدد است: از هر ده سفارش، نه تا سر وقت و سالم رسیده. همین نسبت یک شاخص است: چیزی که کیفیت را از حس به عدد تبدیل میکند — و شاخص سطح خدمت هم همان است، فقط با تعریف دقیق «سر وقت» و «سالم» و یک پنجرهٔ زمانی.You have ordered from the same online shop a dozen times, and now someone asks whether it is reliable. Your answer is a number: nine of ten orders arrived on time and intact. That ratio is an indicator: it turns a feeling about quality into a number — and a service level indicator is the same thing, with “on time”, “intact” and the window defined precisely.
تشبیه و تصویر ذهنیThe analogy
شاخص خوب یک نسبت است، نه یک شمارش: «۹۹.۲ درصد از درخواستهای معتبر، زیر ۳۰۰ میلیثانیه جواب گرفتهاند». صورت و مخرج هر دو مهماند؛ اگر درخواستهای ردشده را از مخرج حذف کنی، عدد زیبا میشود و کاربر همچنان ناراضی است. انتخاب شاخص هم یک تصمیم دربارهٔ این است که چه چیزی برای کاربر مهم است: در دسترس بودن، سرعت، درستی یا تازگی داده. چیزی مثل مصرف CPU شاخص نیست، چون کاربر آن را حس نمیکند؛ نشانه است، نه معیار. بالای این عدد یک هدف میگذاری و پایینش یک توافق، و همانجاست که بحثهای سیاسی شروع میشود.A good indicator is a ratio, not a count: “99.2 percent of valid requests were answered in under 300 milliseconds”. Both parts matter; drop the rejected requests from the denominator and the number looks lovely while users stay unhappy. Choosing the indicator is also a decision about what matters to the user: availability, speed, correctness or freshness of data. Something like CPU usage is not an indicator, because no user feels it; it is a symptom, not a measure. On top of the number you put a target, and under it an agreement, and that is where the politics starts.
و بعدش، فنیAnd now, technically
شاخص سطح خدمت یک اندازهگیری کمی از یک جنبهٔ کیفیت است و مرسومترین شکلش یک نسبت است: تعداد رویدادهای خوب تقسیم بر تعداد رویدادهای معتبر، در یک پنجرهٔ زمانی. سه تصمیم در آن پنهان است. اول، کجا اندازه میگیری: در توزیعکنندهٔ بار، در سرور یا در کلاینت؛ هر سه عدد متفاوتی میدهند، چون صف و شبکه را متفاوت میبینند. دوم، مخرج: درخواستهایی که به خطا خوردهاند و دوباره فرستاده شدهاند جزء کداماند؟ اگر بیرون بگذاری، عدد بهتر میشود و واقعیت بدتر. سوم، نوع شاخص: تأخیر را میشود بهصورت «سهم درخواستهای زیر آستانه» نوشت، که با صدک فرق دارد و برای هدفگذاری بهتر است. شاخص بهتنهایی هدف نیست؛ ورودی هدف سطح سرویس است و پایینتر از آن، ورودی توافق سطح خدمت.A service level indicator is a quantitative measure of one aspect of quality, usually a ratio: good events divided by valid events in a time window. Three decisions hide inside it. First, where you measure: at the load balancer, at the server, or at the client; all three give different numbers because they see queueing and network differently. Second, the denominator: are requests that failed and were retried in or out? Leave them out and the number improves while reality worsens. Third, the shape: latency can be written as the fraction of requests under a threshold, which differs from a percentile and is better for setting targets. The indicator is not the target; it feeds the service level objective, and below that, the service level agreement.
99.9%یعنی از هزار درخواست، یکی میتواند خطا بخوردone request in a thousand may fail
good / validشکل معمول شاخص: نسبت رویداد خوب به رویداد معتبرthe usual shape: good events over valid events
شاخص، هدف، توافقIndicator, objective, agreement
SLISLI
SLOSLO
SLASLA
چیستWhat it is
عدد اندازهگیریشدهa measured number
هدفی برای همان عددa target for that number
تعهد قراردادی با جریمهa contract with penalties
چه کسی تعیین میکندWho sets it
تیم، با تعریف دقیقthe team, defined precisely
تیم، از روی تجربهthe team, from experience
مشتری و فروشندهcustomer and provider
اگر رد شودIf it is missed
یک سیگنال برای بررسیa signal to investigate
بودجهٔ خطا تمام میشودthe error budget burns
جریمه یا خروج از قراردادcredit or a breach
تلهٔ رایجThe usual trap
انتخاب شاخصی که اندازهگیریاش آسان است، نه شاخصی که کاربر حسش میکند. سهم درخواستهای موفق در سرور ممکن است ۹۹.۹٪ باشد، در حالی که کلاینتها timeout میخورند و همان درخواستها را دوباره میفرستند. شاخص را از جایی بخوان که کاربر ایستاده.Picking the indicator that is easy to measure instead of the one users feel. The server-side success rate can read 99.9 percent while clients time out and resend. Read the indicator from where the user stands.
هدف داخلیات را از کجا میآوری؟Where does your internal target come from?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
به مادرت قول دادهای هر شب زنگ بزنی. برای اینکه قول نشکند، هدف واقعیات را میگذاری شش شب از هفت شب؛ یک شب که دیر رسیدی و نشد، هنوز قولت نشکسته. SLO همین است: عددی که برای خودت میگذاری تا آن قول بیرونی نشکند.You promised your mother you would call every night. So the promise survives, your real target is six nights out of seven; one late night when it did not happen has not broken anything. That is an SLO: a number you set for yourself so the outward promise holds.
تشبیه و تصویر ذهنیThe analogy
اگر هدف را هفت شب از هفت بگذاری، هر شبِ ازدسترفته یعنی شکست، و چیزی که همیشه شکسته میشود دیگر انگیزه نیست. اگر سه شب از هفت بگذاری، قول هم معنایش را از دست میدهد. شش از هفت یعنی یک شب اضافه داری که میتوانی خرج کنی: شب مهمانی، شب مریضی، شب کار. تا وقتی آن یک شب سوخته نشده راحت نفس میکشی؛ وقتی سوخت، زنگ زدن را جلو میاندازی. هدف خوب همان نقطهای است که راحت است ولی رایگان نیست.Set the target at seven nights out of seven and every missed night is a failure, and a thing that always fails stops motivating anyone. Set it at three out of seven and the promise means nothing. Six out of seven gives you one spare night you can spend: a party, an illness, a late shift. While that night is unspent you breathe easily; once it is gone you start calling earlier. A good target sits where it is comfortable but not free.
هر ۹ اضافه، بودجهٔ خرابی را ده برابر کوچکتر میکند و هزینهٔ مهندسی را چند برابر.Each extra nine shrinks the downtime budget tenfold and multiplies the engineering cost.
و بعدش، فنیAnd now, technically
SLO هدفی عددی برای یک شاخص کیفیت است، با پنجرهٔ زمانی مشخص: مثلاً ۹۹.۹٪ درخواستها در ۳۰۰ میلیثانیه پاسخ بگیرند، در ۲۸ روز گذشته. سه جزء دارد و اگر یکی نباشد عدد بیمعناست: شاخص (SLI) که از دادهٔ واقعی اندازهگیری میشود، آستانه و صدک (تأخیر p99، نه میانگین)، و پنجره (غلتان یا تقویمی). از SLO یک بودجهٔ خطا بیرون میآید: یک منهای SLO. با ۹۹.۹٪ روی ۲۸ روز حدود ۴۰ دقیقه بودجه داری، و همان بودجه است که استقرارها، مهاجرتها و آزمایشها را میگذراند. SLO را از داده انتخاب کن نه از آرزو: صدکهای فعلی را ببین، بفهم کاربر چه چیزی را تحمل میکند، و هزینهٔ هر ۹ اضافه را حساب کن.An SLO is a numeric target for a quality indicator over a stated window: for example, 99.9% of requests answered within 300 ms over the last 28 days. It has three parts and is meaningless without any of them: the indicator (SLI) measured from real traffic, the threshold and percentile (p99 latency, not the mean), and the window (rolling or calendar). Out of the SLO falls the error budget: one minus the SLO. At 99.9% over 28 days you have about 40 minutes, and that budget is what funds deploys, migrations and experiments. Pick the number from data rather than ambition: look at the current percentiles, learn what users tolerate, and price each extra nine.
99.9%روی ۲۸ روز، حدود ۴۰ دقیقه بودجهٔ خطاover 28 days, about 40 minutes of error budget
1 − SLOبودجهٔ خطا همان یک منهای هدف استthe error budget is one minus the target
28 روزپنجرهٔ غلتان رایج؛ ماه تقویمی رفتار دیگری داردa common rolling window; a calendar month behaves differently
عددی که کار میکند عددی است که مالک داردA number that works is a number with an owner
SLO بدون مالک و بدون داشبورد، یک پوستر است روی دیوار. باید معلوم باشد کدام تیم آن را نگه میدارد، در کدام داشبورد دیده میشود، و وقتی بودجه تمام شد چه اتفاقی میافتد: استقرار متوقف میشود، یا تیم با آگاهی ریسک را قبول میکند. بدون این پیوند، عدد آرامآرام تزئینی میشود و بعد از چند ماه هیچکس یادش نمیآید چرا این عدد انتخاب شده.An SLO with no owner and no dashboard is a poster on the wall. It has to be clear which team holds it, which dashboard shows it, and what happens when the budget runs out: deploys stop, or the team knowingly accepts the risk. Without that link the number slowly turns into decoration, and in a few months nobody remembers why it was chosen.
سختش کن یا شلش کن؟Too tight, or too loose?
SLO خیلی سخت، تیم را فلج میکند: هر تغییر کوچک بودجه را میسوزاند و در نهایت همه یاد میگیرند عدد را دور بزنند. SLO خیلی شل، سیگنال را میکشد: هیچوقت هشدار نمیدهد تا وقتی مشتری هشدار بدهد. راه میانه این است که SLO را کمی سختتر از تجربهٔ امروز بگذاری نه خیلی سختتر، و چند ماه ببینی واقعاً قابل نگهداشتن است یا نه.An SLO that is too tight paralyses the team: every small change burns budget, and eventually everyone learns to route around the number. One that is too loose kills the signal: it never alerts until the customer does. The middle path is to set it slightly tighter than today's experience rather than far tighter, and watch for a few months whether it is genuinely holdable.
تلهٔ رایجThe usual trap
SLO را روی ۱۰۰٪ گذاشتن، یا برابر SLA گذاشتن. با ۱۰۰٪ هیچ استقراری مجاز نیست و تیم یاد میگیرد هشدار را نادیده بگیرد؛ برابر SLA هم یعنی هیچ فاصلهای برای نفس کشیدن نیست، پس اولین استقرار ماه بودجه را میسوزاند.Setting the SLO at 100%, or setting it equal to the SLA. At 100% no deploy is ever allowed and the team learns to ignore the alert; equal to the SLA means no room to breathe, so the first deploy of the month burns the budget.
اگر همین یک قطعه بترکد، چه چیزی سالم میماند؟If this one part dies, what still works?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
پمپ آب ساختمان در زیرزمین است و یدکی ندارد. یک شب میسوزد و صبح همهٔ شش طبقه بیآب هستند؛ لولهها سالماند، شیرها سالماند، ولی آبی نیست. بعد پمپ دوم میخری و خیالت راحت میشود، تا وقتی یادت بیفتد کلیدی که بین دو پمپ جابهجا میکند هم فقط یکی است.The building's water pump sits in the basement with no spare. One night it burns out and all six floors are dry by morning; the pipes are fine, the taps are fine, there is just no water. So you buy a second pump and relax, until you remember that the switch that moves between the two pumps is also a single one.
تشبیه و تصویر ذهنیThe analogy
افزونگی همیشه گرانتر از آن است که به نظر میرسد. پمپ دوم یعنی هزینهٔ خرید، سرویس سالانهٔ دو دستگاه، یک تابلو برق که باید تصمیم بگیرد کدام روشن باشد، و کسی که وقتی پمپ اول سوخت سر وقت آن را عوض کند. اگر تابلو خراب شود، دو پمپ سالم هیچ کاری نمیکنند. بدتر از همه، پمپ یدکیای که سه سال روشن نشده ممکن است همان شب اول کار نکند، چون کسی هرگز امتحانش نکرده.Redundancy always costs more than it looks. A second pump means the purchase, two annual services, a switchboard that has to decide which one runs, and somebody to swap it in on the night the first one dies. If the switchboard fails, two healthy pumps do nothing. Worst of all, a spare that has not run for three years may not start on the first night, because nobody ever tested it.
یک نسخه خرابی را به توقف کامل تبدیل میکند؛ دو نسخه آن را پنهان میکند، به قیمت یک انتخابگر تازه.One copy turns a failure into an outage; two copies hide it, at the price of a new chooser.
و بعدش، فنیAnd now, technically
SPOF قطعهای در مسیر بحرانی است که نسخهٔ دومی ندارد؛ اگر بمیرد کار کل سیستم تمام است. پیدا کردنش با قدم زدن در مسیر یک درخواست شروع میشود: از DNS و load balancer تا سرور برنامه، دیتابیس، صف و سرویسهای کنارش، و هر جا پرسیدن «اگر این بمیرد چه چیزی هنوز کار میکند؟». افزونگی سه چیز میخواهد و اگر یکی نباشد اسمش افزونگی است ولی اثرش نیست: نسخهٔ دوم که واقعاً آماده است، تشخیصی که خرابی را ببیند، و تصمیمی که ترافیک را جابهجا کند. هر سهٔ اینها خودشان میتوانند SPOF تازه باشند؛ انتخابگر، آدرس مجازی، رکورد DNS، و آن یک نفری که کلید استقرار را دارد.A SPOF is a component on the critical path with no second copy; if it dies, the work stops. Finding them starts by walking one request's path, from DNS and the load balancer through the application servers, the database, the queue and the side services, asking at each step: if this dies, what still works? Redundancy needs three things, and without any one of them it is redundancy in name only: a second copy that is genuinely ready, detection that notices the failure, and a decision that moves traffic. Each of those can itself become the new SPOF: the chooser, the virtual address, the DNS record, and the one person holding the deploy key.
1یک نسخه کافی است تا کل مسیر بخوابدone copy is enough to stop the whole path
2×هزینهٔ سختافزار نسخهٔ دوم، پیش از هزینهٔ هماهنگیthe hardware cost of a second copy, before coordination
3نسخه، تشخیص، تصمیم: هر سه لازم استa copy, detection, a decision: all three
SPOFهایی که در دیاگرام نیستندThe SPOFs that are not in the diagram
دیاگرام معماری سه سرور و یک دیتابیس نشان میدهد و هیچکدام از اینها را نشان نمیدهد: رکورد DNS که فقط یک نفر میتواند عوض کند، گواهی TLS که تاریخ انقضا دارد، خط لولهٔ ساخت که تنها راه انتشار است، سرویس پیکربندی مشترک، و کتابخانهای که همه به یک نسخهاش وابستهاند. خیلی از خرابیهای واقعی از همینجا میآیند، نه از قطع شدن یک سرور. عادت خوب این است که هر چند ماه فهرستی بنویسی از چیزهایی که «اگر این تنها باشد، ما میخوابیم».The architecture diagram shows three servers and a database and none of these: the DNS record only one person can change, the TLS certificate with an expiry date, the build pipeline that is the only way to ship, the shared configuration service, and the library everyone depends on at one version. A lot of real outages start here, not with a server dying. A good habit is to write, every few months, a list of the things that would stop you if they were the only one.
افزونگی همزادRedundancy with a shared fate
دو نسخه که سرنوشت مشترک دارند افزونگی نیستند. دو replica روی یک رک، در یک منطقه، پشت یک سوئیچ، با یک نسخهٔ کد و یک خط لولهٔ استقرار، در واقع یک نسخهاند که دو اسم دارد. همان باگ در هر دو اجرا میشود، همان استقرار هر دو را همزمان پایین میآورد، و همان قطعی برق هر دو را خاموش میکند. سؤال درست این نیست که «چند نسخه داریم»، بلکه «این دو نسخه در چه خرابیهایی با هم میمیرند».Two copies with a shared fate are not redundant. Two replicas on one rack, in one zone, behind one switch, running one code version from one deploy pipeline are really one copy with two names. The same bug runs in both, the same deploy takes both down at once, and the same power cut switches both off. The right question is not how many copies you have, but which failures kill these two together.
تلهٔ رایجThe usual trap
«دو نسخه داریم، پس SPOF نداریم.» دو نسخه در یک منطقه، یا یک failover که هیچکس هرگز اجرا نکرده، همان SPOF است با خیال راحت. بکاپی که یک بار هم restore نشده، بکاپ نیست.“We have two copies, so we have no single point of failure.” Two copies in one zone, or a failover nobody has ever run, is the same SPOF with a calmer feeling. A backup that has never been restored is not a backup.
درخواست بعدیات به سرور دیگری برسد، مشکلی هست؟If your next request lands on another server, does anything break?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
هر باجهٔ بانک میتواند کارت را بگیرد و کار را انجام دهد، چون اطلاعات حسابت در سیستم مرکزی است، نه در کشوی همان باجه. اگر هر باجه دفتر کاغذی خودش را داشت، باید همان باجهٔ قبلی را پیدا میکردی. بیحالت بودن یعنی همین: هیچچیزِ مخصوص تو روی میز باجه نمیماند.Any teller at the bank can take your card and do the transaction, because your account lives in the central system, not in that teller's drawer. If each teller kept a paper ledger, you would have to find the same teller again. Being stateless is that: nothing about you stays on the counter.
تشبیه و تصویر ذهنیThe analogy
بیحالت بودن یعنی حالت جابهجا شده، نه اینکه حذف شده باشد. حالت میرود در دیتابیس، در کش مشترک یا در خود کلاینت. سودش روشن است: هر نسخه میتواند هر درخواست را جواب بدهد، پس افزودن نسخه ساده است، ریاستارت شدن یک نسخه کسی را اذیت نمیکند و نیازی به چسبیدن کاربر به یک نسخه نیست. بهایش هم روشن است: هر درخواست باید برای خواندن حالت یک رفتوبرگشت اضافه بزند و آن منبع مشترک میتواند خودش گلوگاه شود. برای همین سیستمهای بیحالت فشار را از روی سرویس برمیدارند و روی دیتابیس میگذارند؛ اگر آنجا جواب ندهد، مشکل فقط جابهجا شده است.Stateless means the state moved, not that it vanished. It went into the database, a shared cache, or the client itself. The gain is obvious: any instance can answer any request, so adding one is easy, restarting one bothers nobody, and no user has to stick to a particular instance. The price is equally clear: every request needs an extra round trip to fetch the state, and that shared source can become the bottleneck itself. Stateless services move pressure off the service and onto the database; if the database cannot take it, the problem has only moved.
بیحالت یعنی حالت جابهجا شده، نه حذف؛ سادگی مقیاس را میخری و یک رفتوبرگشت اضافه میپردازی.Stateless means the state moved, not vanished: you buy easy scaling and pay one extra round trip.
و بعدش، فنیAnd now, technically
در طراحی سرویس، بیحالت یعنی پروسه هیچ دادهٔ مخصوص یک کلاینت را بین دو درخواست نگه ندارد؛ نه نشست در حافظه، نه فایل محلی که فقط روی همان ماشین معنا دارد. نتیجهاش این است که توزیعکنندهٔ بار میتواند هر درخواست را به هر نسخهای بدهد و لازم نیست نشست را به یک نسخه بچسباند. همین یک تصمیم، آپدیت غلتان، مقیاس افقی و جابهجایی در خرابی را ساده میکند. هزینهاش دو چیز است: یک خواندن اضافه برای هر درخواست، و وابستگی کامل به منبع مشترک حالت. اگر آن منبع کش شود یا تکنسخه باشد، همان چیزی که قرار بود حذف شود برمیگردد. در عمل «بیحالت» یک طیف است، نه برچسب: کش محلی، اتصالهای باز و صفهای درونپروسهای هم حالتاند، فقط کوتاهعمر. و برای نوشتنهای تکراری، همان بیحالتی کار را سخت میکند، چون سرور نمیداند این درخواست را قبلاً دیده یا نه، مگر اینکه کلید idempotency را خودت بدهی.In service design, stateless means the process keeps no client-specific data between two requests: no session in memory, no local file that only means something on that machine. As a result the load balancer may send any request to any instance and does not need to pin a session to one. That single decision makes rolling upgrades, horizontal scaling and failover simple. It costs two things: an extra read per request, and total dependence on the shared state store. If that store is a cache or a single node, the thing you were trying to remove comes straight back. In practice stateless is a spectrum, not a badge: a local cache, an open connection and an in-process queue are all state, just short-lived. And repeated writes get harder, because the server cannot tell whether it has seen this request before unless you supply an idempotency key.
1 lookupهر درخواست یک خواندن حالت از منبع مشترکeach request costs one state lookup in the shared store
N → N+1افزودن نسخه، بدون جابهجا کردن نشستadd an instance without moving sessions
تلهٔ رایجThe usual trap
گفتن «سرویس ما بیحالت است» در حالی که نشست در حافظهٔ پروسه است و فقط با session-stickiness کار میکند. روزی که یک نسخه ریاستارت شود یا توزیعکننده تصمیم دیگری بگیرد، کاربر از حساب بیرون میافتد.Claiming the service is stateless while the session sits in process memory and only works with session stickiness. The day one instance restarts, or the balancer picks differently, the user is logged out.
میانگین خوب است؛ پس چرا مشتری عصبانی است؟The average looks fine. Why is the customer angry?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
نانوایی سر کوچه معمولاً سه دقیقهای نانت را میدهد. هفتهای یک بار آدمی جلوی صف چهل نان سفارش میدهد و تو بیستوپنج دقیقه میایستی. میانگین همان سه دقیقه است، ولی تو برنامهٔ ناهارت را دور همان روز بد میچینی؛ تأخیر دنباله همان روز بد است و میانگین آن را پنهان میکند.The bakery on the corner usually hands you your bread in three minutes. Once a week someone at the front orders forty loaves and you stand there for twenty-five. The average is still three minutes, but you plan lunch around the bad day; tail latency is that bad day, and the average hides it.
تشبیه و تصویر ذهنیThe analogy
اگر یکی از صد سفرت با اتوبوس چهل دقیقه طول بکشد و بقیه بیست دقیقه، میانگین چیزی حدود بیستودو دقیقه میشود و هیچ مشکلی به نظر نمیرسد. ولی وقتی قرار مهمی داری، با بیست دقیقه راه نمیافتی؛ با سی دقیقه راه میافتی، چون آن یک سفر را یادت مانده. کسبوکارها هم همین کار را میکنند: وقت اضافه میگذارند، دوباره تلاش میکنند، یا از خیر کار میگذرند. دنباله هزینهای است که در هیچ جدولی نوشته نمیشود ولی همه میپردازند.If one bus trip in a hundred takes forty minutes and the rest take twenty, the average lands near twenty-two and nothing looks wrong. But when you have an appointment you do not leave with twenty minutes to spare; you leave with thirty, because that one trip stayed with you. Businesses do the same: they add slack, they retry, or they give up on the task. The tail is a cost nobody writes in a table and everybody pays.
شکل معمول یک سرویس: میانه ارزان است و دنباله چند برابر گران؛ محور ارتفاع، تأخیر نسبی است.The usual shape of a service: the median is cheap, the tail is many times dearer; bar height is relative latency.
و بعدش، فنیAnd now, technically
تأخیر دنباله یعنی رفتار توزیع در صدکهای بالا: p99 و p999. میانگین شکل توزیع را قایم میکند؛ دو سرویس با میانگین ۵۰ میلیثانیه میتوانند یکی همیشه ۵۰ باشد و دیگری ۴۹ میلیثانیه با یک درصد دو ثانیهای. دنباله از صف میآید، نه از کد کند: وقتی بهرهبرداری از ظرفیت بالا میرود، انتظار در صف غیرخطی رشد میکند و یک انفجار کوچک صف بلندی میسازد. وقفهٔ جمعآوری زباله، افتادن کش، فشردهسازی پسزمینه و همسایهٔ پرسروصدا هم هر کدام چند دهم درصد درخواستها را به دنباله میفرستند. اندازهگیری درست با هیستوگرام است نه با میانگین میانگینها؛ و برای دیدن p999 در یک پنجره باید دستکم هزار درخواست در آن پنجره داشته باشی.Tail latency is the behaviour of the distribution at high percentiles: p99 and p999. The mean hides the shape; two services both averaging 50 ms can be one that always takes 50 and one that takes 49 with one percent at two seconds. The tail comes from queues rather than slow code: as utilisation climbs, waiting in the queue grows non-linearly and a small burst builds a long queue. Garbage-collection pauses, cache misses, background compaction and a noisy neighbour each push a fraction of a percent of requests into the tail. Measure with histograms, not with averages of averages; and to see p999 in a window you need at least a thousand requests in that window.
p99یک درصد کندترین درخواستها؛ همانهایی که تیکت میسازندthe slowest one percent, the ones that open tickets
1000 reqبرای دیدن p999 در یک پنجره، دستکم هزار نمونه لازم استyou need at least a thousand samples to see p999 in a window
10×فاصلهٔ رایج p99 از میانه در سرویسهای واقعیa common gap between p99 and the median in real services
چرا میانگین دروغ میگویدWhy the mean lies
میانگین یک عدد است و توزیع یک شکل. سرویسی با میانگین ۴۰ میلیثانیه و p99 دو ثانیه، از دید میانگین سالم است و از دید کاربر هر پنجاه درخواست یک بار شکنجه. بدتر، میانگینگیری از میانگینها از نظر ریاضی غلط است: میانگین دقیقههای یک ساعت، میانگین آن ساعت نیست، چون تعداد درخواست هر دقیقه فرق میکند. راه درست این است که توزیع را در سطح درخواست نگه داری و صدک را از همان حساب کنی.The mean is a number and a distribution is a shape. A service averaging 40 ms with a p99 of two seconds looks healthy by its mean and tortures a user once every fifty requests. Worse, averaging averages is mathematically wrong: the mean of per-minute means is not the mean of the hour, because the request count differs each minute. The right way is to keep the distribution at request level and compute percentiles from that.
دنباله از کجا میآیدWhere the tail comes from
بخش زیادی از دنباله تقصیر کد نیست؛ تقصیر صف است. وقتی ظرفیتت نزدیک اشباع است، چند درخواست همزمان کافی است تا صف بلند شود و هر کسی که پشت آن است دیر جواب بگیرد. وقفهٔ جمعآوری زباله، خواندن از دیسک بهجای حافظه، یک فشردهسازی شبانه و یک همسایهٔ پرمصرف روی همان ماشین، همه به یک جا اضافه میشوند. برای همین سراغ دنباله رفتن یعنی یا ظرفیت را بالا ببر، یا کارهای پسزمینه را از مسیر کاربر جدا کن، یا صف را با timeout و load shedding کوتاه نگه دار.Much of the tail is not the code's fault; it is the queue's. When utilisation is near saturation, a few simultaneous requests are enough to build a queue and make everyone behind it wait. A GC pause, a read from disk instead of memory, a nightly compaction and a busy neighbour on the same host all land in the same place. So chasing the tail means raising capacity, moving background work off the user's path, or keeping the queue short with timeouts and load shedding.
میانگین در برابر صدک ۹۹Mean versus p99
میانگینMean
صدک ۹۹p99
چه میگویدWhat it tells you
حال کلی سیستمthe general state
بدترین تجربهٔ رایجthe worst common experience
چه پنهان میکندWhat it hides
دنبالهٔ کندthe slow tail
بخش سالم و پرشمارthe large healthy majority
کِی گمراه میکندWhen it misleads
وقتی یک درصد کند، عدد را تکان نمیدهدwhen one percent is slow and the number does not move
وقتی تعداد نمونه کم استwhen there are too few samples
چطور بهتر میشودHow to improve it
کمکردن کار هر درخواستless work per request
کوتاهکردن صف و وقتگیرهاshorter queues and fewer stalls
تلهٔ رایجThe usual trap
بهینهکردن میانگین و گزارش آن. میانگین ۴۰ میلیثانیه است و داشبورد سبز، ولی هر چند دقیقه یک مشتری تایماوت میخورد، چون یک درصد درخواستها دو ثانیهای است و همان یک درصد است که تجربه را میسازد.Optimising and reporting the mean. The mean is 40 ms and the dashboard is green, yet a customer times out every few minutes, because one percent of requests take two seconds and that one percent is the experience.
چرا یک کندی کوچک، کل صفحه را کند میکند؟Why does one small slowdown stall the whole page?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
برای شام هشت غذا داری و همه باید همزمان روی میز باشند. هر غذا معمولاً بیست دقیقهای آماده میشود، ولی یکی از بیست بار نیم ساعت بیشتر طول میکشد. با هشت غذا، احتمال اینکه دستکم یکی عقب بیفتد از یک در بیست خیلی بیشتر است و سر میز منتظر همان یکی میمانند.You have eight dishes to make for dinner and they all have to hit the table together. Each takes about twenty minutes, but one time in twenty it takes an extra half hour. With eight dishes the chance that at least one lags is far above one in twenty, and the table waits for that one.
تشبیه و تصویر ذهنیThe analogy
حسابش ساده است: اگر هر غذا با احتمال یک درصد دیر شود، با هشت غذا احتمال دستکم یک دیرکرد حدود هشت درصد میشود و با صد غذا نزدیک شصتوسه درصد. حالا هر چه بیشتر موازی کنی، مطمئنتر به یک کندی میخوری. راهحل هم سریعتر کردن میانگین نیست؛ کوتاهکردن دنباله است: زودتر با یکی از غذاها شروع کنی و اگر دیر شد، بقیه را بدون آن ببری سر میز. این کار یک چیز را قربانی میکند: پذیرفتن اینکه گاهی یک بخش ناقص میرسد، بهجای اینکه کل میز منتظر بماند.The arithmetic is plain: if each dish is late with one percent probability, with eight dishes the chance of at least one being late is about eight percent, and with a hundred it is nearly sixty-three. The more you parallelise, the more surely you meet a laggard. The fix is not a faster average but a shorter tail: start one dish early and, if it slips, take the rest to the table without it. That sacrifices something: accepting that one part sometimes arrives incomplete instead of keeping the whole table waiting.
هر چه فراخوانهای موازی بیشتر، احتمال برخورد با یکی از کندها بالاتر؛ با صد فراخوان به دو سوم میرسد.The more parallel calls, the likelier one of them is slow; at a hundred calls it is two in three.
و بعدش، فنیAnd now, technically
در یک درخواست fan-out، زمان پاسخ با کندترین فرزند تعیین میشود، نه با میانگین فرزندها. اگر هر فراخوان مستقل با احتمال p از آستانه بگذرد، احتمال اینکه کل درخواست از آن آستانه بگذرد یک منهای (یک منهای p) به توان n است؛ با p برابر یک درصد و صد فراخوان، حدود ۶۳ درصد. یعنی سرویسی با SLO ۹۹.۹٪ وقتی پشت صد فراخوان موازی مینشیند تقریباً همیشه یک کندی دارد. سه راهحل رایج: درخواست پشتیبان که بعد از صدک ۹۵ به نسخهٔ دوم هم بزنی و اولی را ول کنی، کوتاهکردن fan-out با کش و دستهکردن، و برگرداندن جواب ناقص با timeout بهجای منتظر ماندن. اگر همان فراخوانها پشت سر هم و نه موازی باشند داستان برعکس میشود: تأخیرها جمع میشوند و هر کندی کوچک، کل مسیر را بلند میکند.In a fan-out request the response time is set by the slowest child, not by the average child. If each independent call exceeds a threshold with probability p, the chance the whole request exceeds it is one minus (one minus p) to the power n; at p of one percent and a hundred calls that is about 63%. A service with a 99.9% SLO sitting behind a hundred parallel calls is therefore almost always serving a slow one. Three common answers: a hedged request sent at the 95th percentile with the first cancelled, shrinking the fan-out with caching and batching, and returning a partial answer on timeout instead of waiting. Make the same calls serial rather than parallel and the story inverts: the latencies add up and any small stall lengthens the whole path.
1 − 0.99^100با صد فراخوان و یک درصد کندی، احتمال برخورد حدود ۶۳ درصدa hundred calls at one percent slow gives about 63%
≈ 63%همان عدد به زبان درصد؛ نزدیک دو نفر از سه نفرthe same number as a percentage; nearly two in three
p95درخواست دوم را بعد از صدک ۹۵ بفرست، نه از اولsend the second request after p95, not from the start
بودجهٔ SLO را تقسیم کنDivide the SLO budget
اگر SLO انتها-به-انتها ۹۹.۹٪ است و مسیرت صد فراخوان دارد، هر فراخوان نمیتواند ۹۹.۹٪ باشد؛ باید خیلی سختتر باشد یا تعداد فراخوانها کمتر شود. خیلی از تیمها همان عدد را روی هر سرویس میگذارند و بعد تعجب میکنند که زنجیره عدد را رد میکند. حساب سرانگشتی این است که سهم خطای هر فراخوان باید چیزی حدود سهم خطای کل تقسیم بر تعداد فراخوانها باشد، و این با n بزرگ به سرعت غیرواقعی میشود؛ پس راه واقعی، کمکردن n است.If the end-to-end SLO is 99.9% and the path makes a hundred calls, each call cannot be 99.9%; it has to be much tighter, or there have to be fewer calls. Many teams put the same number on every service and then wonder why the chain misses it. The back-of-envelope rule is that each call's error share should be roughly the total error share divided by the number of calls, which quickly becomes unrealistic as n grows; so the real answer is to shrink n.
هزینهٔ اضافهبارThe bill for shorter tails
هر راهحلی که دنباله را کوتاه میکند جای دیگری هزینه دارد. درخواست پشتیبان یعنی تا حدود یک دهم بار اضافه روی سرویس کند، دقیقاً وقتی که آن سرویس حال خوبی ندارد. timeout کوتاهتر یعنی خطای بیشتر و احتمال بیشتر اینکه یک کار دو بار انجام شود. جواب ناقص یعنی کاربر چیزی را نمیبیند و باید بفهمد چرا. هیچکدام رایگان نیست؛ انتخاب درست به این بستگی دارد که کدام هزینه را میتوانی بدهی.Every way of shortening the tail costs something elsewhere. A hedged request puts roughly a tenth of extra load on the slow service, exactly when that service is unwell. A shorter timeout means more errors and a higher chance a piece of work happens twice. A partial answer means the user does not see something and has to understand why. None of these is free; the right choice depends on which cost you can afford.
تلهٔ رایجThe usual trap
همان SLO را روی هر فراخوان و روی کل مسیر گذاشتن. هر سرویس ۹۹.۹٪ است، زنجیره ۹۹٪ میشود، و کسی نمیفهمد چرا. بدتر، اضافهکردن retry وقتی دنباله کند است، بار را دقیقاً روی همان سرویس خراب دو برابر میکند.Putting the same SLO on every call and on the whole path. Every service is at 99.9%, the chain lands near 99%, and nobody can see why. Worse, adding retries while the tail is slow doubles the load on exactly the service that is struggling.
در یک ساعت چند تا، یا هر کدام چقدر طول میکشد؟How many per hour, or how long does each one take?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
برای اردوی مدرسه باید سی ساندویچ بسازی. یکییکی که بسازی، هر ساندویچ دو دقیقهات را میگیرد و اولی سریع آماده است. ولی اگر همهٔ نانها را بچینی و بعد همه را پر کنی، سی تا را در نیم ساعت تمام میکنی؛ فقط اولین ساندویچ خیلی دیرتر آماده میشود. گذردهی همان «چند تا در نیم ساعت» است و تأخیر همان «اولی کِی آماده میشود».You have to make thirty sandwiches for a school trip. One at a time, each takes two minutes and the first is ready quickly. But if you lay out all the bread first and then fill them all, you finish thirty in half an hour; only the first sandwich is ready much later. Throughput is the how-many-in-half-an-hour; latency is when the first one is ready.
تشبیه و تصویر ذهنیThe analogy
دستهکردن برای همین است: یک کار گران را یک بار برای همه انجام میدهی، نه یک بار برای هر کدام. یک سفر به سوپرمارکت برای بیست قلم ارزانتر از بیست سفر است، ولی تا وقتی برنگردی هیچکدام از قلمها در خانه نیست. در آشپزخانه هم گلوگاه همان مرحلهای است که از همه کندتر است؛ اگر فر را سریع کنی ولی آمادهکردن مواد ده دقیقه بگیرد، هیچچیز عوض نمیشود. سقف گذردهی را همیشه تنگترین مرحله تعیین میکند.That is what batching is for: one expensive step done once for everyone instead of once per item. One trip to the shop for twenty items is cheaper than twenty trips, but until you are back none of the items are in the house. In the kitchen the bottleneck is the slowest stage; speed up the oven while the prep still takes ten minutes and nothing changes. The ceiling on throughput is always set by the tightest stage.
دو تنظیم متفاوت: یکی برای پاسخ سریع به هر کار، یکی برای بیشترین کار در ساعت.Two settings: one for a fast answer to each job, one for the most jobs per hour.
و بعدش، فنیAnd now, technically
گذردهی، تعداد عملیات کاملشده در واحد زمان است: درخواست بر ثانیه، رکورد بر ثانیه، مگابایت بر ثانیه. عدد گذردهی بدون تأخیر و بدون ترکیب بار بیمعناست؛ «ده هزار درخواست بر ثانیه» وقتی p99 دو ثانیه است دستاورد نیست. دستهکردن گذردهی را بالا میبرد چون هزینهٔ ثابت هر عملیات (fsync، سفر شبکه، قفل) بین چند کار تقسیم میشود، ولی تأخیر هر کار را بالا میبرد چون باید منتظر پر شدن دسته بماند. خط لوله هم همین کار را با مراحل موازی میکند. سقف گذردهی را همیشه تنگترین مرحله تعیین میکند، پس سریعکردن مرحلهای که گلوگاه نیست فقط هزینه است. رابطهٔ همزمانی، گذردهی و تأخیر را با قانون لیتل مینویسند: همزمانی برابر است با گذردهی ضربدر تأخیر.Throughput is the count of completed operations per unit of time: requests per second, records per second, megabytes per second. A throughput number without latency and without the workload mix means nothing; ten thousand requests per second at a p99 of two seconds is not an achievement. Batching raises throughput because the fixed cost of each operation (an fsync, a network round trip, a lock) is shared across several jobs, but it raises each job's latency because it must wait for the batch to fill. Pipelining does the same with parallel stages. Concurrency, throughput and latency are tied by Little's law: concurrency equals throughput times latency.
L = λWهمزمانی برابر است با گذردهی ضربدر تأخیرconcurrency equals throughput times latency
p99گذردهی را همیشه همراه با تأخیر همان بار گزارش کنalways report throughput with the latency at that load
1 vs 1000یک سفر برای هزار رکورد، بهجای هزار سفرone round trip for a thousand records instead of a thousand
عددی که بدون تأخیر معنا نداردA number that means nothing without latency
هر عدد گذردهی باید با یک شرط بیاید: در چه تأخیری، با چه ترکیبی از خواندن و نوشتن، و با چه توزیعی از اندازهٔ درخواست. عددی که از یک آزمون بار در نقطهٔ اشباع بیرون میآید بالاترین عدد ممکن است، نه عددی که کاربر تجربه میکند. تیمها این عدد را در اسلاید میگذارند و بعد در تولید میبینند که با نصف آن بار صفها بلند میشوند.Every throughput number has to come with conditions: at what latency, with what read-to-write mix, with what distribution of request sizes. A number taken from a load test at saturation is the highest number possible, not the one a user experiences. Teams put it on a slide and then find in production that queues grow at half that load.
قانون لیتل، به زبان سادهLittle's law, plainly
اگر هر درخواست یک ثانیه طول بکشد و سیستم همزمان صد درخواست را نگه دارد، گذردهی حدود صد درخواست بر ثانیه است. برای دو برابر کردن گذردهی در همان تأخیر باید همزمانی را دو برابر کنی؛ و اگر تأخیر بالا برود، گذردهی میتواند صاف بماند در حالی که تجربهٔ کاربر بدتر شده. خیلی از افتهای گذردهی در واقع افت کیفیت صف است، نه کم شدن ظرفیت.If each request takes a second and the system holds a hundred in flight, throughput is about a hundred per second. To double throughput at the same latency you must double concurrency; and if latency rises, throughput can stay flat while the user's experience gets worse. Many throughput drops are really queue-quality drops, not lost capacity.
تلهٔ رایجThe usual trap
گزارش گذردهی بدون تأخیر، یا اندازهگیری با ابزاری که تا جواب نگیرد درخواست بعدی را نمیفرستد. آن ابزار صف را نمیبیند و عددی میدهد که دنیای واقعی هیچوقت تکرارش نمیکند.Reporting throughput without latency, or measuring with a tool that waits for each answer before sending the next. That tool never sees a queue, and it reports a number the real world never repeats.
همهچیز روی دیسک است؛ پس چرا بعضی روزها سریع است؟It all lives on disk. Why is it fast some days?
مثال روزمره، بدون اصطلاحThe everyday one, no jargon
گوشیات دویست برنامه دارد، ولی روی صفحهٔ اول هشتتا نشسته؛ همانهایی که هر روز باز میکنی. بقیه در کشوی برنامهها هستند و باز کردنشان چند ثانیه بیشتر وقت میبرد. مجموعهٔ کاری همان هشتتاست، و وقتی اپ جدیدی اضافه میکنی یکی باید از صفحهٔ اول برود.Your phone has two hundred apps, but eight sit on the home screen, the ones you open every day. The rest are in the app drawer and take a few extra seconds to reach. The working set is those eight, and when you add a new one, one has to leave the home screen.
تشبیه و تصویر ذهنیThe analogy
صفحهٔ اول جا ندارد؛ همین که همهچیز را رویش بگذاری دیگر صفحهٔ اول نیست، یک کشوی شلوغ است و مزیتش را از دست میدهد. ترکیب آن هشتتا هم ثابت نیست: تابستان اپهای سفر میآیند، ماه رمضان اپ تقویم و غذا. اگر یکی از هشتتا سنگین شود و جای دو تا را بگیرد، آن دو تا هر بار باید از کشو بیرون بیایند و همان چند ثانیه، همان تأخیری است که کاربر حس میکند. بدترین حالت نه وقتی است که مجموعه بزرگ است، بلکه وقتی است که فقط کمی از صفحهٔ اول بزرگتر است؛ آنوقت مدام چیزی را بیرون میگذاری و برمیگردانی.The home screen has no spare room; put everything on it and it is no longer a home screen but a crowded drawer, and the advantage is gone. The eight are not fixed either: travel apps arrive in summer, calendar and food apps during the month of fasting. If one of the eight grows heavy and takes the space of two, those two have to come out of the drawer every time, and those seconds are the latency the user feels. The worst case is not a large set but one only slightly larger than the home screen; then you are constantly pushing something out and pulling it back.
همان داده، دو سرنوشت: اگر مجموعهٔ کاری در حافظه جا شود خواندنها ارزاناند، اگر نه هر خواندن یک سفر است.Same data, two fates: if the working set fits in memory reads are cheap, if not every read is a trip.
و بعدش، فنیAnd now, technically
مجموعهٔ کاری، مجموعهٔ صفحهها یا کلیدهایی است که در یک پنجرهٔ زمانی (مثلاً یک ساعت یا یک روز) دستکم یک بار خوانده یا نوشته میشوند. اگر این مجموعه در حافظه جا شود، خواندنها سرعت حافظه دارند؛ اگر جا نشود، هر عدمبرخورد یک خواندن تصادفی از دیسک یا شبکه است و تأخیر جهش میکند. اندازهٔ کل داده ربط چندانی ندارد: یک پایگاه دادهٔ چند ترابایتی با مجموعهٔ کاری چند گیگابایتی روی ماشینی با رم کافی سریع است، و یک پایگاه دادهٔ کوچک که مجموعهٔ کاریاش از رم بزرگتر است هر شب کند میشود. اندازهگیریاش با نمونهگیری از کلیدهای پرسروصداست: در یک بازه بشمار چند کلید یکتا خوانده میشود و نمودار فراوانی را ببین.The working set is the set of pages or keys read or written at least once inside a time window, say an hour or a day. If that set fits in memory, reads run at memory speed; if it does not, every miss is a random read from disk or the network and latency jumps. Total data size matters much less: a multi-terabyte database with a few-gigabyte working set on a machine with enough RAM is fast, while a small database whose working set exceeds RAM gets slow every night. Measure it by sampling the loud keys: count distinct keys touched in a window and look at the frequency curve.
80/20بخش کوچکی از کلیدها، بخش بزرگتری از دسترسیها را میسازدa small share of keys serves a much larger share of reads
1 missهر بار که داده در حافظه نباشد، یک خواندن از دیسک یا شبکهevery miss is one read from disk or the network
≈ 5%در بسیاری از سرویسها فقط چند درصد داده داغ استin many services only a few percent of the data is hot
پرتگاه، نه شیبA cliff, not a slope
وقتی مجموعهٔ کاری از حافظه بزرگتر میشود، افت تدریجی نیست؛ پرتگاه است. تا نزدیک مرز نرخ برخورد بالا میماند و فقط چند درصد بدتر میشود؛ بعد از مرز، هر افزایش کوچک در مجموعه بخش زیادی از دسترسیها را از حافظه بیرون میاندازد و نرخ برخورد سقوط میکند. برای همین است که تیمها یک روز بیدار میشوند و میبینند سرویس دو برابر کند شده، بدون اینکه ترافیک دو برابر شده باشد: داده کمی رشد کرده و از مرز گذشته.When the working set outgrows memory the fall is not gradual; it is a cliff. Until close to the edge the hit rate holds and degrades by a few percent; past it, every small growth pushes a large share of accesses out and the hit rate collapses. That is why teams wake up one day to a service twice as slow without traffic having doubled: the data grew a little and crossed the edge.
چطور اندازهاش را بگیریHow to size it
سادهترین راه، اندازهگیری نرخ برخورد است: اگر با اضافهکردن رم عدد بالا میرود جای رشد داشتی، و اگر تکان نمیخورد گلوگاه جای دیگری است. راه دقیقتر، نمونهگیری از کلیدهای خواندهشده و شمارش کلیدهای یکتا در پنجرههای زمانی است. یک هشدار: یک پیمایش کامل شبانه میتواند همهٔ حافظه را با دادههای سرد پر کند و مجموعهٔ کاری واقعی را بیرون بیندازد؛ اگر گزارشگیری سنگین داری، مسیرش را از کش داغ جدا کن.The simplest check is the hit rate: if adding RAM moves it, you had headroom to gain, and if it does not move, the bottleneck is elsewhere. A more precise way is to sample the keys being read and count distinct keys per window. One warning: a nightly full scan can fill memory with cold data and evict the real working set; if you run heavy reporting, give it a path away from the hot cache.
تلهٔ رایجThe usual trap
ظرفیت رم را با اندازهٔ کل داده تعیین کردن. کسی میگوید «پنج ترابایت داده داریم، پس پنج ترابایت رم میخواهیم» و بعد معلوم میشود مجموعهٔ کاری چند گیگابایت است. اشتباه دوم، رها کردن یک پیمایش سنگین روی همان کشی است که کاربر به آن تکیه کرده.Sizing RAM by total data. Someone says “we have five terabytes, so we need five terabytes of RAM”, and it turns out the working set is a few gigabytes. The second mistake is letting a heavy scan run through the same cache users depend on.