<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vaibhav Varshney on Medium]]></title>
        <description><![CDATA[Stories by Vaibhav Varshney on Medium]]></description>
        <link>https://medium.com/@vaibhavvarshney008?source=rss-ea65eaa666b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*azmOMawQdxgSrV4NcxpRZg.png</url>
            <title>Stories by Vaibhav Varshney on Medium</title>
            <link>https://medium.com/@vaibhavvarshney008?source=rss-ea65eaa666b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:03:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vaibhavvarshney008/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your Celery Worker Is Not What You Think It Is]]></title>
            <link>https://medium.com/@vaibhavvarshney008/your-celery-worker-is-not-what-you-think-it-is-7ecaa1167531?source=rss-ea65eaa666b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ecaa1167531</guid>
            <category><![CDATA[celery-django]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[celery]]></category>
            <dc:creator><![CDATA[Vaibhav Varshney]]></dc:creator>
            <pubDate>Mon, 10 Aug 2026 11:57:52 GMT</pubDate>
            <atom:updated>2026-08-10T11:57:52.339Z</atom:updated>
            <content:encoded><![CDATA[<h3>Four levels, one ack, and the config that quietly eats your tasks</h3><p>Someone on your team asks a simple question:</p><blockquote>“How many Celery workers are we running?”</blockquote><p>You check the infrastructure console. Twelve instances. You check RabbitMQ. Twelve consumers. Twelve and twelve — great, so twelve workers.</p><p>That answer is probably wrong, and the way it’s wrong hides a class of bugs that will silently delete your background jobs.</p><p>The problem is that <strong>“worker” means three different things</strong>, and most teams use the word for all three interchangeably. Once you separate them, a surprising amount of Celery behaviour stops being mysterious — including why your longest-running tasks occasionally vanish without a trace.</p><p>Let’s untangle it.</p><h3>Part 1 — The four levels</h3><p>There are four distinct things stacked inside what people call “a worker”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sr1q3RukPRGZEUGAX3OtQ.png" /><figcaption>Four levels, one overloaded word. The dashed line is the one that matters most.</figcaption></figure><p><strong>Level 1 — the machine.</strong> The instance, the pod, the container. Infra teams call this “the Celery worker box”, which is where the confusion starts.</p><p><strong>Level 2 — the worker (also called the node, or MainProcess).</strong> This is one celery -A myapp worker process. It owns the TCP connection to the broker, the prefetch window, and — critically — <strong>the ack</strong>. It executes no task code at all.</p><p><strong>Level 3 — the consumer.</strong> This is <em>not</em> a machine and <em>not</em> a process. It’s an AMQP <strong>subscription</strong> — the basic.consume call that says &quot;send messages from this queue to me.&quot; The broker writes it down and hands back a consumer tag. This is what RabbitMQ counts in the Consumers column.</p><p><strong>Level 4 — the child process.</strong> The prefork pool member that actually imports your code and runs the task function. <strong>The broker has never heard of it.</strong></p><p>A box running four workers looks like this:</p><pre>1 machine<br>├── worker-default        --concurrency=3  →  3 children<br>├── worker-notifications  --concurrency=1  →  1 child<br>├── worker-batch          --concurrency=1  →  1 child<br>└── worker-media          --concurrency=1  →  1 child</pre><pre>= 4 workers · 6 children · 10 OS processes · 4 consumer tags</pre><p>One machine. Not one worker.</p><h3>Part 2 — The kitchen</h3><p>If the AMQP vocabulary isn’t landing, here’s the version that makes it stick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-LWYPQryqU2_xuebOQ_51Q.png" /><figcaption>The manager has never met a single line cook.</figcaption></figure><p>The broker is <strong>a wall of rails</strong>. Orders hang there as paper tickets. Each rail is a queue.</p><p>You hire <strong>head chefs</strong>. Each stands in front of one rail. Starting a head chef = running celery worker -Q &lt;rail&gt;. <strong>The head chef is the worker.</strong></p><p>When a chef starts their shift they tell the manager: <em>“I’m watching this rail — send tickets my way.”</em> That announcement is the <strong>consumer</strong>. It’s a raised hand, not a person. The manager writes it in a book.</p><p>Head chefs never cook. They grab a ticket and hand it to a <strong>line cook</strong> behind them. Line cooks are the <strong>child processes</strong>.</p><p>And the manager — the broker — has never met a line cook. He only knows about raised hands.</p><h3>Part 3 — So which shapes are legal?</h3><p>Here’s the question that trips everyone up: <em>can one worker have many consumers, or can one consumer have many workers?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cu5JzeoenEy9PWPVrBVaCA.png" /><figcaption>A worker can have many consumers. A consumer can never have many workers.</figcaption></figure><p><strong>One worker, many consumers — legal.</strong> Pass -Q queue_a,queue_b,queue_c and that single process raises three hands. One worker, three consumer tags.</p><p><strong>Many workers, one queue — legal, and normal.</strong> This is the <em>competing consumers</em> pattern, and it’s how you scale a queue horizontally. Ten boxes each running one worker on the same queue = ten consumers on that queue. They each bring their own hand; they don’t share one.</p><p><strong>Two workers sharing one consumer — impossible.</strong> A consumer is created on a specific worker’s connection and dies with it. Two workers is always two consumers.</p><p>So back to the opening question. If you see twelve instances and twelve consumers, you’re almost certainly looking at <strong>one row</strong> in the queue list — one worker per box on <em>that</em> queue. If each box also runs three other workers, the true totals are 48 workers and 48 consumer tags. The two numbers matched by coincidence of configuration, not because the words mean the same thing.</p><p><strong>The counts only line up when you happen to run exactly one worker per box per queue. Add one comma to a </strong>-Q<strong> flag and they diverge forever.</strong></p><h3>Part 4 — The payoff: who acks, and when</h3><p>Here’s why all that vocabulary was worth the effort.</p><p><strong>The parent acks. Not the child.</strong></p><p>By default, Celery ships with task_acks_late = False. That means the parent process acknowledges the message to the broker <em>the moment it receives it</em> — <strong>before</strong> it hands the payload to a child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1f3yLLwtHNef7RJ439sAQ.png" /><figcaption>The ack happens before any work starts. Everything after that point is unprotected.</figcaption></figure><p>Follow the consequences:</p><ol><li>Parent receives a message for a 4-minute video transcode.</li><li>Parent <strong>acks</strong>. The broker deletes the message. It no longer exists.</li><li>Parent hands the payload to a child.</li><li>Child starts ffmpeg.</li><li>Someone deploys. The process manager restarts the worker.</li><li><strong>The task is gone.</strong> Never redelivered. Nobody is notified.</li></ol><p>And note the failure mode isn’t limited to deploys. Because the <em>parent</em> holds the ack, the message is also lost when the <strong>child</strong> dies — an OOM kill, a segfault, or a --max-tasks-per-child recycle landing at an awkward moment. The parent survives, the consumer stays registered, the broker sees nothing wrong.</p><p>It gets worse if your task marks state before doing work:</p><pre>record.status = &quot;PROCESSING&quot;<br>record.save()<br># ... long work ...<br># except: record.status = &quot;ERROR&quot;</pre><p>A SIGKILL never reaches your except block. So the row sits at PROCESSING <strong>forever</strong>. It doesn&#39;t even show up as a failure — it just quietly stops existing.</p><h3>The fix is two settings, and they must ship together</h3><pre>app.conf.task_acks_late = True<br>app.conf.task_reject_on_worker_lost = True</pre><p>This moves the ack to <em>after</em> the child returns. Anything goes wrong, the message goes back on the queue.</p><p><strong>But check your process manager first.</strong> Celery treats SIGTERM as a warm shutdown (finish in-flight work, then exit) and SIGQUIT as a <strong>cold shutdown</strong> (die immediately). A lot of Supervisor and systemd configs specify QUIT — sometimes copied from a blog post years ago, sometimes to make restarts feel snappy.</p><pre># Supervisor — the version that loses work<br>stopsignal=QUIT<br>stopwaitsecs=30</pre><pre># The version that doesn&#39;t<br>stopsignal=TERM<br>stopwaitsecs=900     # ≥ your longest task</pre><p>Turning on acks_late while still cold-killing workers just converts silent loss into a <strong>redelivery storm</strong> on every deploy. Fix the signal first, or ship both changes together.</p><blockquote>One process-tree gotcha: if your service runs a shell script that launches Celery without <em>exec</em>, the shell stays as the parent — and your <em>stopsignal</em> hits the shell, not Celery. Supervisor&#39;s <em>stopasgroup=true</em> (or systemd&#39;s <em>KillMode=control-group</em>) is what actually gets the signal to the worker. Worth checking before you conclude your warm shutdown works.</blockquote><h3>One prerequisite: idempotency</h3><p>acks_late changes your delivery guarantee from <em>at-most-once</em> to <em>at-least-once</em>. A task can now run twice. Before flipping it, walk your task list and ask: <strong>if this runs twice, what breaks?</strong></p><p>Most well-written tasks are already fine:</p><pre>@shared_task<br>def transcode_video(video_id: int) -&gt; bool:<br>    video = repo.get(id=video_id)</pre><pre>    # Idempotent exit — already done<br>    if video.transcoded_key:<br>        return True</pre><pre>    # deterministic output path — a re-run overwrites, it doesn&#39;t duplicate<br>    ...</pre><p>Guarded exits, get_or_create, deterministic storage keys, state checks before mutation. If your tasks already do these — and most teams&#39; do, because it&#39;s just good practice — acks_late is safe today and you&#39;re leaving durability on the table by not enabling it.</p><h3>Part 5 — Prefetch is the other half of the pair</h3><p>You’ll often see this recommended for long tasks:</p><pre>app.conf.worker_prefetch_multiplier = 1</pre><p>It’s good advice. By default Celery prefetches 4 × concurrency messages into a worker&#39;s buffer, which means one worker can hoard a pile of jobs while its neighbours sit idle. Setting it to 1 stops that.</p><p>But here’s what’s frequently missed: <strong>the limit is per worker, not per child.</strong> It’s a single basic.qos call on the parent&#39;s channel, computed as prefetch_multiplier × concurrency. A worker with --concurrency=3 and multiplier 1 holds three unacked messages, not one.</p><p>And more importantly: prefetch_multiplier=1<strong> and </strong>acks_late=True<strong> are a pair.</strong> Setting only the first is half a pattern. Prefetch limits <em>how many</em> messages a worker buffers; it does nothing for durability, because the one message it holds is already acked.</p><p>Teams often ship the prefetch setting, feel like they’ve handled long-running tasks, and never touch the ack setting. That’s the throughput half with none of the safety half.</p><h3>Part 6 — The default queue becomes a dumping ground</h3><p>Routing in Celery is opt-in. You name a few tasks in task_routes; everything else silently lands on the default queue.</p><p>Which means the default queue accumulates. Six months in, it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jLmtpnM16YkdB07JjHrNg.png" /><figcaption>The queue named “batch” holds four tasks. The genuinely slow work is all on the default.</figcaption></figure><p>The trap: a full-catalog reindex, an unbounded backfill, and a batch of CPU-bound image resizes all sit on the same queue as record_user_interaction and update_user_profile. With --concurrency=3, three long jobs occupy every slot and your fast, user-facing tasks queue behind a full-table scan.</p><p><strong>The tell:</strong> you have a queue named batch (or slow, or low_priority) that holds three or four things, while the default queue holds sixty. The names describe an intention that routing never implemented.</p><p>Worth checking too: task_create_missing_queues defaults to True. A typo in a route (&quot;btach&quot;) silently declares a brand-new queue with <strong>no consumer</strong>, and your tasks vanish into it. If you declare all queues explicitly, turn it off:</p><pre>app.conf.task_create_missing_queues = False</pre><h3>And the scaling trap this sets up</h3><p>When the default queue backs up, the obvious move is to add boxes. It works — for a while. But if the backlog is caused by three batch jobs monopolising every slot, <strong>horizontal scaling is papering over a routing problem.</strong> You end up paying for a large fleet that’s mostly idle, punctuated by bursts where it’s still too slow.</p><p>Fix routing first. Then measure. Then resize.</p><h3>Part 7 — No time limits, and the subprocess problem</h3><p>Check whether you have these set. Most projects don’t:</p><pre>app.conf.task_time_limit = 600       # hard kill<br>app.conf.task_soft_time_limit = 540  # raises SoftTimeLimitExceeded</pre><p>Unset, both default to None — <strong>no limit at all</strong>. A task that hangs pins its slot forever. On a queue with --concurrency=1, one hung task stops the entire queue. Nothing alerts, because the task never <em>fails</em>; it just never finishes. That&#39;s a far worse failure mode than a crash.</p><p>There’s a nastier version of this if you shell out:</p><pre># Don&#39;t do this<br>result = os.system(f&quot;ffmpeg -i {filepath} ... {output}&quot;)</pre><p>Three problems in one line:</p><ol><li><strong>No timeout is possible.</strong> os.system has no timeout parameter, and a soft time limit can&#39;t meaningfully interrupt a thread blocked in system(3).</li><li><strong>Shell injection.</strong> That f-string goes through a shell. If filepath ever comes from user input or an external URL, you have a vulnerability.</li><li><strong>You can’t read stderr</strong> to find out why it failed.</li></ol><pre># Do this<br>completed = subprocess.run(<br>    [&quot;ffmpeg&quot;, &quot;-i&quot;, filepath, &quot;-threads&quot;, &quot;3&quot;, ..., output],<br>    capture_output=True,<br>    timeout=3300,<br>    check=False,<br>)<br>if completed.returncode != 0:<br>    raise RuntimeError(f&quot;ffmpeg failed: {completed.stderr[-500:]}&quot;)</pre><p>One edit closes the injection, adds a real timeout, and gives you diagnosable errors.</p><h3>Part 8 — The hidden CPU tenant</h3><p>This one is genuinely sneaky, and it breaks every capacity calculation on the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjqkrFZXL0GY8HuCYUwBig.png" /><figcaption>One child. Eight cores. Celery has no idea.</figcaption></figure><p>You budget CPU by counting children: 8 vCPU, 6 children, comfortable.</p><p>But if one of those children shells out to a <strong>multi-threaded subprocess</strong> — ffmpeg, ImageMagick, a compiler, NumPy with a threaded BLAS backend — that subprocess doesn’t respect your concurrency setting. libx264 auto-detects cores and takes all of them. Your &quot;1 child&quot; is an 8-vCPU tenant.</p><p>While that task runs, every other worker on the box is fighting it for cores. Your fast queue slows down for reasons that show up nowhere in Celery’s metrics, because Celery cannot see the subprocess.</p><p><strong>Two ways out:</strong></p><ol><li><strong>Cap the subprocess.</strong> -threads 3 for ffmpeg, OMP_NUM_THREADS for BLAS, --jobs for compilers. Your budget becomes honest.</li><li><strong>Split the fleet.</strong> Media boxes run one worker at concurrency 1 and let the subprocess have the whole machine. General boxes never run that queue. Same image, different -Q flags.</li></ol><p>Option 2 is usually right at scale, because CPU-heavy work and request-driven work rarely scale together.</p><h3>Part 9 — ETA and countdown tasks evaporate</h3><pre>expire_upload.apply_async(args=[upload_id], countdown=3600)</pre><p>Looks harmless. Here’s what actually happens: <strong>Celery pulls that message off the broker immediately</strong> and holds it in the worker’s memory for the full hour, waiting for its ETA.</p><p>With acks_late=False, a restart during that hour drops it. Silently. And with deploys happening a few times a day, a one-hour countdown has a meaningful chance of never firing.</p><p>If you rely on scheduled tasks, you need a <strong>sweeper cron</strong> as a safety net:</p><pre>@shared_task<br>def requeue_overdue_jobs() -&gt; None:<br>    &quot;&quot;&quot;Hourly safety net — re-queues ETA tasks lost on worker restart.&quot;&quot;&quot;<br>    for record in repo.get_pending_due_within_next_hour():<br>        if record.due_at &lt;= now():<br>            do_the_thing.delay(record.id)<br>        else:<br>            do_the_thing.apply_async(args=[record.id], eta=record.due_at)</pre><p>Teams usually build exactly one of these — after getting burned once — and then never apply the pattern to the <em>other</em> three places they use countdown=. Go grep for eta= and countdown= in your codebase and check each one has a net.</p><h3>Part 10 — So how many workers should a box run?</h3><p>Back to the original question, now that it’s answerable. It’s really <strong>two</strong> questions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0RYXkWOaHjwBiGEW-9WbQ.png" /><figcaption>Workers is a routing decision. Children is a capacity decision.</figcaption></figure><pre>how many WORKERS  =  how many QUEUES this box should serve   (routing)<br>how many CHILDREN =  --concurrency                            (capacity)</pre><p>Worker parents hold a socket and a prefetch window. They cost a rounding error of CPU. <strong>Capacity lives entirely in </strong>--concurrency<strong>.</strong></p><p><strong>Step 1 — classify each queue.</strong> CPU-bound work should roughly match your vCPU count. I/O-bound work (HTTP calls, waiting on a database) can be oversubscribed heavily — a prefork child blocked on a socket costs ~0 CPU and one full interpreter of RAM. That’s the trade: oversubscribing I/O is cheap in CPU, expensive in memory. For heavily I/O-bound queues, consider a gevent pool instead, where concurrency 50 costs about one core. (Note: --max-tasks-per-child is prefork-only and must be dropped when you switch pools.)</p><p><strong>Step 2 — use Little’s Law, not intuition.</strong></p><pre>concurrency = arrival rate (tasks/sec) × average task duration (sec)</pre><p>20 tasks/sec at 200ms each → you need <strong>4</strong> slots. Not 40. Pull both numbers per task from your APM and compute per queue. Add ~2× headroom for burst.</p><p><strong>Step 3 — check the one signal that actually matters.</strong></p><pre>rabbitmqctl list_queues name messages_ready messages_unacknowledged consumers</pre><ul><li>messages_ready ≈ 0 all day → over-provisioned. Cut.</li><li>climbing and not draining → under-provisioned, or blocked downstream.</li><li>messages_unacknowledged should sit near consumers × concurrency when busy.</li></ul><p>Watch it across a full daily cycle. Cron-driven workloads are spiky by construction, and a number sampled at 3pm tells you very little about 3am.</p><p><strong>Step 4 — watch the consumer count.</strong> This is the monitoring gap almost nobody closes. If a worker dies on a few boxes, the consumer count drops and <strong>nothing tells you</strong>. The queue keeps accepting messages and growing. Without a result backend, and with worker_send_task_events off by default, nothing is watching completion either.</p><p>Alert on consumers &lt; expected per queue. It&#39;s a five-minute setup that catches an entire category of silent outage.</p><h3>Takeaways</h3><p><strong>Worker, consumer, and machine are three different things.</strong> A worker is a process you start. A consumer is a subscription the broker records. A machine holds many of both. They only look identical when your config happens to be one-worker-per-box-per-queue.</p><p><strong>The parent acks, not the child.</strong> That single fact explains why in-flight tasks disappear on deploys, on OOM kills, and on process recycles — and why task_acks_late is the highest-leverage setting in a default Celery install.</p><p>prefetch_multiplier=1<strong> without </strong>acks_late=True<strong> is half a pattern.</strong> You get the fair distribution and none of the durability.</p><p><strong>Routing is opt-in, so the default queue silently becomes everything.</strong> Check the spread before you check the box count — adding machines to fix a routing problem is expensive and doesn’t work.</p><p><strong>Celery cannot see your subprocesses.</strong> A shelled-out encoder or compiler will take every core on the box, and no Celery metric will tell you.</p><p><strong>Count queues to get workers. Run Little’s Law to get children.</strong> And remember that one media-processing child may secretly cost you eight cores.</p><p><em>If your fleet is bigger than your queue depth justifies, the answer usually isn’t more boxes. It’s finding out which three tasks are sitting on the wrong queue.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ecaa1167531" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Cassandra Partitioning & Sharding: The Concept That Finally Made It Click]]></title>
            <link>https://medium.com/@vaibhavvarshney008/understanding-cassandra-partitioning-sharding-the-concept-that-finally-made-it-click-ec3c96f7d370?source=rss-ea65eaa666b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec3c96f7d370</guid>
            <category><![CDATA[database-sharding]]></category>
            <category><![CDATA[sharding]]></category>
            <category><![CDATA[partition]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[partitioning]]></category>
            <dc:creator><![CDATA[Vaibhav Varshney]]></dc:creator>
            <pubDate>Sat, 01 Aug 2026 17:35:20 GMT</pubDate>
            <atom:updated>2026-08-01T17:37:28.265Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started reading about <a href="https://www.educative.io/blog/slack-system-design-interview">Slack’s system design,</a> one line kept appearing:</p><blockquote><em>“Messages are partitioned by channel ID.”</em></blockquote><p>Sounds simple.</p><p>But then I started wondering:</p><ul><li>Does Cassandra create millions of partitions?</li><li>Does every partition become a separate file?</li><li>If Slack has 100 million channels, does Cassandra create 100 million storage objects?</li><li>How is this different from PostgreSQL partitioning?</li><li>And where does sharding fit into all this?</li></ul><p>It took me a while to realize that the biggest source of confusion wasn’t Cassandra itself — it was the word <strong>partition</strong>.</p><p>Let’s build the intuition from scratch.</p><h3>The Biggest Misconception</h3><p>When most people hear the word <em>partition</em>, they imagine something like this:</p><pre>📁 channel-1<br>📁 channel-2<br>📁 channel-3</pre><p>As if Cassandra creates one folder or one file for every channel.</p><p>It doesn’t.</p><p>Not even close.</p><h3>Think About a Python Dictionary</h3><p>Suppose you have this dictionary:</p><pre>messages = {<br>    &quot;channel-1&quot;: [...],<br>    &quot;channel-2&quot;: [...],<br>    &quot;channel-3&quot;: [...]<br>}</pre><p>How many files exist?</p><p>Just one.</p><p>The dictionary internally stores millions of keys.</p><p>It doesn’t create one file per key.</p><p>Cassandra works much more like this than like a filesystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtiMDP2-hrNl12v8XUtnJA.png" /><figcaption>Python dictionary analogy</figcaption></figure><h3>Understanding Cassandra’s Primary Key</h3><p>Consider this schema:</p><pre>CREATE TABLE messages (<br>    channel_id text,<br>    sequence bigint,<br>    message text,<br>    PRIMARY KEY ((channel_id), sequence)<br>);</pre><p>This one line explains almost everything.</p><p>Let’s break it down.</p><pre>PRIMARY KEY (<br>    (channel_id),<br>    sequence<br>)</pre><p>Notice something unusual.</p><p>There are <strong>two sets of parentheses.</strong></p><p>Those parentheses have completely different meanings.</p><h3>The Partition Key</h3><p>The first parentheses:</p><pre>(channel_id)</pre><p>tell Cassandra:</p><blockquote><em>Keep all rows having the same </em><em>channel_id together.</em></blockquote><p>Imagine these rows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ejo_GcalE5tdVgsT-kT9qQ.png" /></figure><p>Cassandra groups them like this:</p><pre>Partition: general</pre><pre>1 → Hello<br>2 → Hi<br>3 → Bye</pre><pre>--------------------</pre><pre>Partition: random</pre><pre>1 → Welcome<br>2 → Thanks</pre><p>Every channel becomes one logical partition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4u2Lr_GFG-ZWBdYhCGr7A.png" /><figcaption>Drawer/partition visualization</figcaption></figure><h3>The Clustering Column</h3><p>Now look at the second part:</p><pre>sequence</pre><p>This is called the <strong>clustering column</strong>.</p><p>It tells Cassandra:</p><blockquote><em>Inside each partition, store rows ordered by sequence.</em></blockquote><p>Instead of:</p><pre>3<br>1<br>2</pre><p>the partition becomes</p><pre>1<br>2<br>3</pre><p>That’s perfect for chat applications because conversations are naturally ordered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gIR51MNEoI9huUDkIkiPA.png" /><figcaption>Ordered messages inside one partition</figcaption></figure><h3>Why Not Make Both Columns the Partition Key?</h3><p>Imagine we wrote:</p><pre>PRIMARY KEY ((channel_id, sequence))</pre><p>Now every message gets its own partition.</p><pre>(general,1)</pre><pre>(general,2)</pre><pre>(general,3)</pre><p>Loading a channel would require reading thousands of different partitions.</p><p>That would completely defeat the purpose.</p><p>Instead,</p><pre>PRIMARY KEY ((channel_id), sequence)</pre><p>creates exactly one partition per channel.</p><h3>So What Is Actually a Partition?</h3><p>This is the key realization.</p><p>A Cassandra partition is <strong>not</strong>:</p><ul><li>a file</li><li>a folder</li><li>a table</li><li>a database</li></ul><p>A partition is simply:</p><blockquote><strong><em>All rows having the same partition key.</em></strong></blockquote><p>That’s it.</p><p>Nothing more.</p><h3>Does Cassandra Create Millions of Partitions?</h3><p>Yes.</p><p>And that’s completely normal.</p><p>Suppose Slack has:</p><ul><li>50 million channels</li></ul><p>Then Cassandra has roughly:</p><ul><li>50 million logical partitions.</li></ul><p>That sounds scary until you realize these aren’t separate storage objects.</p><p>Think of a huge Excel sheet:</p><p>ChannelSequenceMessagegeneral1Hellogeneral2Hirandom1Welcomerandom2Thanks</p><p>Every unique channel represents one logical partition.</p><p>The data still lives inside the same table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5V60R2OYtkm0WyV3RTHnxA.png" /><figcaption>Excel sheet grouped by channel</figcaption></figure><h3>So Where Is The Data Actually Stored?</h3><p>Internally Cassandra stores data inside <strong>SSTables</strong>.</p><p>Imagine one huge sorted file.</p><pre>SSTable</pre><pre>channel-1<br>    msg1<br>    msg2<br>    msg3</pre><pre>channel-2<br>    msg1<br>    msg2</pre><pre>channel-3<br>    msg1</pre><p>There isn’t one file per channel.</p><p>Instead, the file simply contains groups of rows sharing the same partition key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EyQwM3UwbFNjR0t9smBLhg.png" /><figcaption>SSTable layout</figcaption></figure><h3>How Does Cassandra Find The Right Partition?</h3><p>Suppose Slack asks:</p><pre>SELECT *<br>FROM messages<br>WHERE channel_id=&#39;general&#39;;</pre><p>Does Cassandra scan the whole table?</p><p>No.</p><p>Each SSTable maintains metadata like:</p><ul><li>Partition Index</li><li>Partition Summary</li><li>Bloom Filter</li></ul><p>These help Cassandra jump directly to the required partition instead of scanning millions of rows.</p><h3>Enter Sharding</h3><p>Everything we’ve discussed so far works even if Cassandra has only one machine.</p><p>Now let’s add more nodes.</p><pre>Node A</pre><pre>Node B</pre><pre>Node C</pre><p>What happens now?</p><p>Cassandra hashes the partition key.</p><pre>hash(channel_id)</pre><p>The hash decides which node stores the partition.</p><p>For example:</p><pre>channel-1 → Node A</pre><pre>channel-2 → Node C</pre><pre>channel-3 → Node B</pre><p>This process is called <strong>sharding</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hc1DM1AMZXv3SCgwFGSP3w.png" /><figcaption>Cluster showing partitions distributed across nodes</figcaption></figure><h3>Partitioning vs Sharding</h3><p>This was the biggest realization for me.</p><p>Partitioning and sharding are not the same thing.</p><p>Instead, they happen one after another.</p><pre>Grouped into partitions</pre><pre>↓</pre><pre>Partitions distributed across nodes</pre><p>In other words:</p><ul><li>Partitioning groups related rows together.</li><li>Sharding distributes those groups across machines.</li></ul><h3>Why Doesn’t Cassandra Use PostgreSQL-style Partitions?</h3><p>Because PostgreSQL partitioning means something completely different.</p><p>In PostgreSQL:</p><pre>messages</pre><pre>├── messages_2025<br>├── messages_2026<br>├── messages_2027</pre><p>Each partition is an actual physical table.</p><p>Every partition has:</p><ul><li>separate storage</li><li>separate indexes</li><li>separate statistics</li></ul><p>In Cassandra,</p><p>there is still only one table.</p><p>The partition is simply a logical grouping of rows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bywx04Sg01nOE8hPkPasAQ.png" /><figcaption>PostgreSQL vs Cassandra comparison</figcaption></figure><h3>The Filing Cabinet Analogy</h3><p>This analogy finally made everything click for me.</p><p>Imagine a filing cabinet.</p><p>Each drawer represents one Slack channel.</p><pre>Drawer: #general</pre><pre>1<br>2<br>3<br>4</pre><p>Another drawer:</p><pre>Drawer: #random</pre><pre>1<br>2</pre><p>The drawer is the partition.</p><p>The numbered documents inside are ordered by the clustering column.</p><p>Now imagine having millions of drawers.</p><p>Those drawers are spread across multiple filing cabinets.</p><p>Each filing cabinet represents a Cassandra node.</p><p>That’s essentially how Cassandra works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0wIZVesg2axMxS8WXZUWw.png" /><figcaption>Filing cabinet analogy for Cassandra</figcaption></figure><h3>The Mental Model I’ll Remember Forever</h3><p>Whenever I see this:</p><pre>PRIMARY KEY ((channel_id), sequence)</pre><p>I now read it like this:</p><ul><li>channel_id</li><li>Which bucket does this row belong to?</li><li>Which node stores that bucket?</li><li>sequence</li><li>In what order should rows be stored inside the bucket?</li></ul><p>That’s it.</p><p>Everything else in Cassandra — efficient reads, scalability, SSTables, consistent hashing, and even Slack’s message storage architecture — builds on this single idea.</p><p>Sometimes the hardest part of learning distributed systems isn’t the algorithms.</p><p>It’s simply understanding what a single overloaded word like <strong>partition</strong> actually means.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec3c96f7d370" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually is Markup Language? Why we are using it? What it is solving?]]></title>
            <link>https://medium.com/@vaibhavvarshney008/what-actually-is-markup-language-why-we-are-using-it-what-it-is-solving-5665787f0218?source=rss-ea65eaa666b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5665787f0218</guid>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[markup-language]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[xml]]></category>
            <dc:creator><![CDATA[Vaibhav Varshney]]></dc:creator>
            <pubDate>Sun, 31 Mar 2024 20:28:25 GMT</pubDate>
            <atom:updated>2024-03-31T20:28:25.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>WHAT ARE MARKUP LANGUAGES?</h3><p>It’s simply a language that is used by computer to specify the structure and formatting of a document. It helps the machine to understand the structure and style of the content. You may infer from a word analysis of “markup” that markup languages are used to describe specific details about a document’s content.</p><p>Let’s understand it with an example:-</p><p>Suppose you have a large box with lots of blocks in it and every block functions as a unique tag that provides information about what it is and how it should appear. When we use these blocks to build something, like a castle or a car, we’re using a markup language. We can more easily understand and appreciate our work because to the tags (blocks) that help us organise and beautify it.</p><p>It is totally different from programming languages. Markup language is made to focus on <strong>presentation and structure of content</strong> while Programming language is used to create <strong>functional and dynamic web applications.</strong></p><h4><strong>What it is solving?</strong></h4><p>A markup’s language main purpose is to provide an robust solution for the organising and formatting digital material. It addresses a number of significant issues and meets a demand in the fields of communication and information technology.<br>Such as:</p><p><strong>1. Structuring and Organizing the document: </strong>Markup languages help organize content by defining its structure, such as headings, paragraphs, lists, tables, and more. This structured approach makes content easier to read, understand, and navigate.</p><p><strong>2. Controlling the presentation:- </strong>Markup language allow the authors to control the presentation of document with the control over the formatting elements like fonts, colors, styles, alignment, and layout with the guarantee of an attractive and consistent appearance across all platforms and devices.</p><p><strong>3. Togetherness(or Interoperability):- </strong>Markup language make it easier for data to be interchanged and for various platforms, apps, and systems to work together. Data can be represented in a way that is easily interpreted, parsed, and processed by a variety of software applications by using a standard markup language.</p><p><strong>4. Accessibility:- </strong>Markup languages can make content elements more accessible by giving semantic information about them. By understanding HTML tags, assistive technologies — like screen readers — can use this information to improve accessibility for people with disabilities and give audio descriptions of web material.</p><p><strong>5. Managing the content:- </strong>Markup languages help to document workflows and content management systems (CMS). For the purpose of efficiently creating, editing, organising, and publishing content — whether it be web pages, papers, articles, or data records — they offer an organised framework.</p><h4><strong>MARKUP LANGUAGES</strong></h4><h4><strong>GenCode</strong></h4><p>GenCode was the first public markup language presentation in computer text processing.</p><h4><strong>Generalized Markup Language</strong></h4><p>In the early 1970s, GML called the Generalized Markup Language was developed where every tag would be defined like the following. and it is the the first standard descriptive markup language.</p><p>Its syntax is something like this.</p><p><strong>“:h1.Your heading”</strong></p><p>IBM uses GML as description language on IBM i and predecessors for objects called “panel groups”. Later it converted to SGML.</p><h4><strong>HTML</strong></h4><p>One of the most popular markup language is <strong>HTML. </strong>In early 90’s, Sir Tim Berners-Lee wrote a memo proposing an Internet-based hypertext system, then specified HTML and wrote the browser and server software. It stands for Hypertext Markup Language. This language represents the foundation of the World Wide Web. It is used to display content on web browsers.</p><p>A sample HTML document looks like this,</p><p>&lt;HTML&gt;</p><p>&lt;HEAD&gt;</p><p>&lt;TITLE&gt; Title of the webpage &lt;/TITLE&gt;</p><p>&lt;/HEAD&gt;</p><p>&lt;BODY&gt;</p><p>Content of the document goes here</p><p>&lt;/BODY&gt;</p><p>&lt;/HTML&gt;</p><h4><strong>XML</strong></h4><p>XML Stands for Extensible Markup Language. developed by the <strong>World Wide Web Consortium</strong> in a committee created and chaired by Jon Bosak. XML’s primary goal was to simplify SGML by concentrating on a specific issue: online documents. Like SGML, XML is still a meta-language that lets users define whatever tags that are required, and then describes those tags and the uses that are allowed.</p><p>A sample XML file looks like this,</p><p><strong>&lt;?xml</strong> version=”1.0&quot; encoding=”ISO-8859–1&quot;<strong>?&gt;</strong></p><p><strong>&lt;note&gt;</strong></p><p><strong>&lt;to&gt;</strong>Tove<strong>&lt;/to&gt;</strong></p><p><strong>&lt;from&gt;</strong>Jani<strong>&lt;/from&gt;</strong></p><p><strong>&lt;heading&gt;</strong>Reminder<strong>&lt;/heading&gt;</strong></p><p><strong>&lt;body&gt;</strong>Don’t forget me this weekend!<strong>&lt;/body&gt;</strong></p><p><strong>&lt;/note&gt;</strong></p><h4><strong>XHTML</strong></h4><p>XHTML was developed to make HTML more extensible and increase interoperability with other data formats. In addition, browsers were forgiving of errors in HTML, and most websites were displayed despite technical errors in the markup. It is introduced with stricter error handling.</p><p>A sample XHTML file looks like this,</p><p>&lt;!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”<br>“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;<br>&lt;html xmlns=”http://www.w3.org/1999/xhtml&quot;&gt;<br>&lt;head&gt;<br> &lt;title&gt;XML Transitional Template&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</p><p><em>some content here…</em></p><p>&lt;/body&gt;<br>&lt;/html&gt;</p><h3>CONCLUSION</h3><p>We have discussed what markup languages are in this post, what they are solving, some points regarding the purpose of markup language and talked about markup languages like GenCode, GML, SGML, HTML, XML, XHTML. Also we have discussed about the difference between a markup language and a programming language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5665787f0218" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>