Rate Limiting Is Not Just a Redis INCR Call

Ask most engineers to build a rate limiter and you get the same answer: INCR a Redis key, set a 60 second TTL, reject when the count crosses the limit. It ships, it passes the demo, and it is wrong in a way that will not show up until a real client with real burst behavior hits it in production. That INCR counter is a fixed window, and a fixed window has a specific, exploitable failure mode that lets a client send double its limit in a two second span. ...

14 min

Corporate Bond Funds vs FD vs Debt Funds: Post-Tax in 2026

Since April 2023, the standard advice has flattened into a shrug: “debt funds and FDs are taxed the same now, so just pick whatever.” That is lazy and it is costing 30% bracket investors real money. Yes, the headline tax rate is identical. FD interest, debt fund gains and corporate bond fund gains are all taxed at your income slab in 2026. But identical tax rate does not mean identical post-tax return. The gap comes from when the tax is charged, the gross yield you start with, and what you give up in liquidity. For a 3-5 year parking of ₹10 lakh, that gap is worth roughly ₹30,000-35,000. Not life-changing, but not nothing, and it is free. ...

8 min

Design Distributed Queue (RabbitMQ-like) - System Design

There are two completely different things people call “a message queue,” and confusing them is the fastest way to fail this interview. One is a log - Kafka-shaped, an append-only tape where the broker is dumb, never deletes on read, and every consumer tracks its own position. The other is a broker - RabbitMQ-shaped, a smart mailbox where the broker owns each message, hands it to exactly one consumer, waits for an acknowledgment, and redelivers if that ack never comes. This post builds the second one, because the requirements name it: at-least-once delivery, priority queues, dead-letter queues. Those are broker features. A log does not track per-message delivery state, cannot prioritize one message over another sitting behind it, and has no notion of “this message was rejected three times, send it somewhere else.” A smart broker does. ...

30 min

Design Google Analytics Pipeline - System Design

Everyone thinks Google Analytics is a counter with a chart on top. “Drop a snippet on every page, count the pageviews, draw a line graph, done.” Then the interviewer piles on the constraints that make it a real system: it is not one website, it is billions of them, each a separate tenant that must only ever see its own data; it is not a thousand hits, it is 100 billion events a day landing from every corner of the internet; the product does not show one number, it shows a live “users on site right now” ticker and “sessions per day for the last 18 months” and “of everyone who saw the product page, what fraction added to cart then checked out” and “of the users who first showed up in March, how many came back in April.” Those are four completely different query shapes over the same firehose, and one of them (unique users) cannot even be answered exactly at this scale without melting. ...

33 min

Design Google Calendar - System Design

“Design Google Calendar” sounds like a CRUD app: a user creates an event, it shows up in a grid, the phone syncs it. The interviewer lets that run for a minute, then asks the four questions the toy version cannot answer. First: a user creates “team standup, every weekday at 9am, forever” - do you really write one row per day until the heat death of the universe? Second: someone opens the scheduling assistant, picks eight coworkers across four timezones, and expects to see everyone’s free-busy for next Tuesday in under a second. Third: a billion users have reminders set, and each must fire within a few seconds of its due time even though “due time” depends on the attendee’s timezone and DST rules. Fourth: I edit an event on my laptop offline on a plane, my phone edits the same event, and both must converge without losing data when I land. ...

31 min

Zero-Downtime Deployments Are Hard - Especially When the Database Changes

Most “zero-downtime deployment” tutorials show you two identical stacks, a load balancer, and a switch you flip from blue to green. Traffic moves, nobody notices, everyone claps. That demo works because the demo has no database, no long-lived connections, and no in-flight work. Every hard part of a real deployment is exactly the part the demo removed. The honest version: swapping stateless web servers is a solved problem. The moment your deploy also changes a database schema, drops a websocket, or invalidates a session, “zero downtime” becomes a set of design constraints on your application code, not a checkbox on your CI pipeline. This post walks the naive blue-green picture, breaks it on purpose, and maps each failure mode to a pattern that actually handles it. ...

11 min

Design Distributed Stream Processing System (Kafka-like) - System Design

“Stream processing” sounds like a for loop over a queue: read a message, do a thing, write a result. That mental model dies the moment the thing you do has memory. Count events per user per minute, and now you have state - which user is at what count, and what happens to that count when the machine holding it dies mid-minute? Read late-arriving events, and now “per minute” is a lie, because messages do not arrive in the order they happened. Ask for exactly-once, and now a crash between “read”, “update the count”, and “write the result” cannot be allowed to double-count or drop, across three different systems at once. A durable log that just moves bytes is the easy half. The hard half is running stateful computation over that log at a million messages a second per topic without losing, duplicating, or mis-ordering a single result when a node inevitably falls over. ...

32 min

Design Top K Most Shared Articles in Time Windows - System Design

Everyone thinks top-K is a SELECT article_id, COUNT(*) FROM shares GROUP BY article_id ORDER BY count DESC LIMIT 100. Store every share, group, sort, take the top 100, done. Then the interviewer adds the constraints that make it a real problem: it is not one all-time ranking, it is three sliding windows at once - the top 100 in the last 5 minutes, the last hour, and the last 24 hours; there are 100 million articles; there are a billion shares a day, spiking hard when something goes viral; and the answer has to be near-real-time, so a share that just happened should be able to move an article onto the list within a second or two, not on the next hourly batch. ...

28 min

Design Yelp / Nearby Friends - System Design

“Nearby Friends” looks like the Uber problem wearing a different hat - a map, some dots, find the ones near me. It is not. Uber asks “out of 5 million strangers moving around, who is the single nearest one,” and answers it with a spatial nearest-neighbour index. Nearby Friends asks a different and in some ways nastier question: “out of my friends specifically, which ones are within 5km of me right now, and keep that answer live as both of us walk around.” The set you care about is not “everyone near this point” - it is the intersection of two things that both change every few seconds: the social graph (who is my friend, who opted in) and live geography (who is physically close). The hard part is the fan-out: when I move, which friends need to be told, and when a friend moves, do I need to know? Do that naively for 50M concurrently-moving people each with hundreds of friends and you generate billions of pointless distance checks a second. ...

30 min

Sovereign Gold Bonds Maturing in 2026: What Holders Actually Earned

Most SGB articles you will read are a forecast: buy this, hold eight years, and here is a hypothetical CAGR. That era is over. The first big tranches issued in 2018 have now hit their eight-year maturity, so we can stop guessing and read the receipt. This post takes one specific bond that matured a couple of months ago, works out to the rupee what a holder actually walked away with, and lines it up against a gold ETF and physical gold bought on the very same day. ...

8 min

Testing LLM Apps Is Nothing Like Testing Regular Code

Here is the assertion that breaks every engineer coming to LLM apps from normal software: assert output == expected is useless. You cannot write it. The same prompt, the same model, the same temperature, and you still get two different strings on two runs. Even at temperature zero you get drift across model versions, across providers routing you to a different GPU, across a retried request. The equality check that anchors all of regular testing is gone. ...

13 min

Design Distributed Metrics & Log Aggregation - System Design

Everyone underestimates log aggregation because the demo is trivial: run an agent on a box, ship each line over the network, dump it into a searchable store, done. Then the interviewer sets the actual scale - 100,000 servers, ~10M events per second, retain 30 days, query it all from a dashboard - and every part of the trivial version dies. Ten million events a second is roughly 3 GB/sec on the wire and hundreds of terabytes a day; a single server’s agent hiccuping cannot be allowed to drop your incident forensics; the read pattern is a schizophrenic mix of “aggregate this numeric metric over a range” and “grep for this rare error string across a petabyte in the last 30 days”; and the naive fix - “just index every word so search is fast” - is precisely the decision that makes your index bigger than your data and bankrupts the cluster. ...

31 min

Design Pastebin - System Design

Pastebin looks like a URL shortener with a bigger payload, and people design it that way: mint a key, stuff the text somewhere, return a link. Then the interviewer pushes. Where does the actual paste body live - in the database? What happens to your row size and your backups when someone pastes a 5MB stack trace? How do you serve a billion reads a day when each response is not a 500-byte redirect but a 10KB blob? How do 100 million pastes expire without a cron job melting the database? Now it is a real system. ...

22 min

Design Stock Exchange Order Matching - System Design

“Match buy and sell orders” sounds like a database join. Then you look at the constraints. A million orders a second arrive from thousands of members. Two orders for the same stock at the same price must fill in the exact order they arrived - not roughly, exactly - because that ordering is money and it is legally auditable. The same stream of orders replayed on a backup machine must produce byte-for-byte the same trades, or your failover invents fills that never happened. A single mismatched fill is a broken trade, a regulatory incident, and a lawsuit. This is not a CRUD service with a queue in front. It is a deterministic state machine that happens to be one of the most latency-sensitive pieces of software people build. ...

34 min

Liquid Fund vs Savings Account vs Sweep-In FD for Your Buffer

Most people put their emergency fund in a savings account and never think about it again. That single default, held for years on a fund that might run to four, five, six lakh, quietly costs more than any expense-ratio debate people love to have about their equity SIPs. A savings account paying 2.75% against a liquid fund near 6.75% is a gap of roughly 4% a year on money that is supposed to be a boring safety net. ...

11 min

Using AI Agents to Modernize Legacy Code - What Actually Works

If you have watched a demo where an AI agent “modernizes” a codebase in one shot, you have watched a toy. Point the same agent at a real system - 200,000 lines of PHP 5 with no tests, three generations of ORM, and business logic smuggled inside stored procedures - and it will produce confident garbage. It will rename things, break the build in ways the build does not report, and quietly change behavior that nobody wrote down anywhere. ...

14 min

Design an Airbnb / Hotel Booking System - System Design

“Design Airbnb” sounds like a listings app: a host posts a room, a guest searches a city, they book, money changes hands. The interviewer lets that run for a minute, then asks the two questions the toy version cannot answer. First: a guest in Bangalore types “Goa, 24-27 December, 2 guests” and expects, in under a second, the handful of places that are actually free for those exact three nights out of millions of listings. Second: two guests, on two continents, both tap “book” on the same beach villa for overlapping dates at the same instant. Exactly one of them can win, and the loser must never receive a confirmation for a villa that is already taken. ...

30 min

Design Instagram-like Photo Sharing - System Design

Instagram sounds like Twitter with pictures, and half of it is. The follow graph, the feed of people you follow, the celebrity who breaks fan-out - all of that is the same problem the news feed poses, and I will not pretend otherwise. But the other half is the part people wave away in interviews and then drown in: a photo is not 280 bytes of text, it is a 3MB blob that has to be uploaded over a flaky phone connection, resized into five renditions, stored durably forever, and then served from an edge cache to millions of people in under 100ms. At 100M uploads a day that media pipeline is its own distributed system, and it is where this design actually gets hard. ...

24 min

Design Netflix Recommendation Engine - System Design

The recommendation engine is the product. Netflix does not have a search box you visit with intent; it has a home screen that must guess, before you type anything, which of ~100,000 titles you want to watch tonight - and it must guess differently for you than for the 200M other people staring at their own home screens. Get it wrong and the user scrolls for four minutes, gives up, and cancels next month. The naive framing (“show popular stuff”) dies immediately: popularity is the same for everyone, and the whole point is that it must not be. The real problem is this: for every one of 200M users, score a catalog of ~100,000 titles against everything we know about that user, return the top few dozen ranked for their taste in under ~100ms, and shift those recommendations within seconds of them finishing an episode - without re-scoring 100,000 titles per user per request, and without waiting hours for a nightly batch job to notice they just binged a new genre. ...

32 min

Super Top-Up vs a Higher Base Health Cover: The Premium Math

The default advice is “buy the biggest base health cover you can afford.” It is also the most expensive way to reach a high sum insured. If your goal is Rs. 25 lakh of protection for your family, buying it as one Rs. 25 lakh base policy can cost you 30-40% more every year than building the same Rs. 25 lakh out of a modest base plus a super top-up. ...

11 min