<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cesar Vega</title>
    <description>The latest articles on DEV Community by Cesar Vega (@gvegacl).</description>
    <link>https://dev.to/gvegacl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1128584%2Fc27dccfd-e528-4c2d-8bd0-ecf3f4fcdda4.png</url>
      <title>DEV Community: Cesar Vega</title>
      <link>https://dev.to/gvegacl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gvegacl"/>
    <language>en</language>
    <item>
      <title>Local AI is a Fun Hobby. It’s Also Terrible Economics for Real Work.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Sat, 28 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/gvegacl/local-ai-is-a-fun-hobby-its-also-terrible-economics-for-real-work-2k2d</link>
      <guid>https://dev.to/gvegacl/local-ai-is-a-fun-hobby-its-also-terrible-economics-for-real-work-2k2d</guid>
      <description>&lt;p&gt;This might age poorly — I hope it does.&lt;/p&gt;

&lt;p&gt;I have been building my gaming PC for years; I probably started in 2021, slowly. At first, I didn’t even get a GPU since my favorite strategy games were CPU-heavy, not GPU-heavy (Why wasn’t I into flight simulator instead of Civilization…)&lt;/p&gt;

&lt;p&gt;Over the years, I ended up with an RTX 3080 with 12GB of VRAM and 64GB of DDR5 RAM. Just between the RAM and the GPU, I’ve probably spent $1000 USD. And my rig is OKAY for local LLMs if we use architectures like Strata or quantized models; they even run at a solid 50 tok/s.&lt;/p&gt;

&lt;p&gt;Here’s the important part — I feel good using my local LLMs; I feel in control of my data, every piece of my prompt, and I know there are no prompt controls or predetermined limits on what I can do.&lt;/p&gt;

&lt;p&gt;I started getting bolder; I connected my Hermes and PI CLIs to my local LLM, and it worked! I could have 100k+ context windows and code! Completely local! — And the code quality was good! Inkling 2 Mini is as good as Opus 4.7 was; can you believe that?&lt;/p&gt;

&lt;p&gt;But I’m going to put a damper on the celebration. There are two huge issues I found:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;My personal machine is unusable… I have to keep a close eye on my RAM when doing anything. I can’t keep more than one agent running at a time, and my agents are also capped since they can’t run scripts that might use a couple of gigabytes of RAM; my whole compute is dedicated to keeping the LLM alive. — I never dared to open a game while my local LLM was running.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s not worth it unless you have a very niche (or abliterated) requirement. The math doesn’t make sense for local LLMs. — I can understand if you are not convinced about the math if you have only used Codex or Claude Code, but there are many providers out there that literally give away millions of free tokens.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even once you move past the free tiers on aggregators like OpenRouter, discount providers charge pennies per million tokens for the same open weights. Spending $10 a month on something like OpenCode Go buys tens of millions of coding tokens at datacenter speed. I even tested the classic local-AI counterargument: running Strata 24/7 with a background job querying it every 5 minutes. That adds up to 8,640 calls a month, and it still wouldn’t burn through my free tokens or my $10 OpenCode Go subscription. Put that next to the $1,000 I already spent on my RTX 3080 and 64GB of DDR5, and locking up my whole machine to save a few dollars a month on tokens is a bad trade. On cloud APIs, I can run three or four Hermes or PI agents in parallel alongside Docker containers, test suites, and twenty browser tabs without babysitting my RAM.&lt;/p&gt;

&lt;p&gt;For real work, local LLMs make sense in only two narrow cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abliterated or uncensored weights: You want zero refusals, zero prompt filters, and nobody logging what you type on a remote server; running weights on your own hardware is the only guarantee.&lt;/li&gt;
&lt;li&gt;Hard privacy rules or no Wi-Fi: You work under an NDA that bans external APIs, touch regulated data, or want basic autocomplete on a flight.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anywhere else, buying tokens wins. Maybe in two years unified-memory desktops get cheap enough that this post ages poorly — I’d be happy to be wrong.&lt;/p&gt;

&lt;p&gt;Until then, I’m keeping Strata installed, and I’m not selling my GPU. Tinkering with local LLMs gives me the same kick as building a PC part by part; you learn how VRAM limits and KV caches behave up close, and you feel like a teen escaping Big Brother for an afternoon — but it is a hobby. Let someone else’s data center pay the RAM tax for your coding agents, and leave the RTX 3080 free for Civilization.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Gemini Notebook is amazing and YOU should try it.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Wed, 25 Nov 2026 17:18:27 +0000</pubDate>
      <link>https://dev.to/gvegacl/gemini-notebook-is-amazing-and-you-should-try-it-3k2d</link>
      <guid>https://dev.to/gvegacl/gemini-notebook-is-amazing-and-you-should-try-it-3k2d</guid>
      <description>&lt;p&gt;I usually use Antigravity CLI and spend most of my Google AI Pro subscription on code. But last week, I discovered Gemini Notebook when I was trying to make some interactive quizzes to learn about system design - And let me tell you - I looked for bronze and discovered gold.&lt;/p&gt;

&lt;h1&gt;
  
  
  Notebook Context.
&lt;/h1&gt;

&lt;p&gt;Notebook's magic is how it handles context. It lets you manage context beautifully; it can ingest books, videos, pictures, text, and other Gemini conversations, so you have everything you need for a specific project without polluting your chats with the details of every conversation, if you don't want to. &lt;/p&gt;

&lt;p&gt;For example, I am working on figuring out the architecture and system design of a website, so I added a bunch of videos (It can ingest YouTube videos with a click), books, and some deep research documents I built in Gemini about my product. &lt;/p&gt;

&lt;p&gt;If you try to add all that information in a single chat, you run into a few problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The individual chat context gets filled quickly, and the model performance degrades.&lt;/li&gt;
&lt;li&gt;It's annoying if you want to start many conversations with the same starting "knowledge base".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Notebook also has the STUDIO.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Studio.
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhp1nel0ygph7x8auy04p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhp1nel0ygph7x8auy04p.png" alt=" " width="457" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I used to ignore these options in the studio, but now that I have used them, I can vouch for them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Audio overview (And interactive mode).
&lt;/h3&gt;

&lt;p&gt;I used to think these would be butchered and off-theme, but they are quite good - Google can generate a 1h podcast-like discussion about any topic you want, supported by your sources.&lt;br&gt;
&lt;strong&gt;Interactive mode&lt;/strong&gt;: I tried this, but it's a bit buggy for me; maybe it'll improve in the future. But I love the concept of "talking" with the LLM live while it has your sources as a knowledge base.&lt;/p&gt;

&lt;h3&gt;
  
  
  Video overview.
&lt;/h3&gt;

&lt;p&gt;This feature can make ~6-minute videos about any topic; it reminds me of those old infographic videos. They are usually good quality and excellent for visual learners.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mind maps, reports, quizzes, flashcards, infographics.
&lt;/h3&gt;

&lt;p&gt;These are features I often use when studying: flashcards and quizzes are amazing for testing whether you are actually retaining the information you are studying.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Overall, I think people might not be aware of how useful Gemini Notebook is, and I also think Google might have made it harder for people to find it since you need to click an inconspicuous link in the top-right of the page to actually go to the notebook:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6wcwtwz77vyid8q9plie.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6wcwtwz77vyid8q9plie.png" alt=" " width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image of the notebook site:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92wz53edbjwt1qxiemdx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92wz53edbjwt1qxiemdx.png" alt=" " width="799" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What do you think? Should Google make it more obvious how to access the notebook? - Do Anthropic or OpenAI have similar features? &lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>discuss</category>
      <category>tools</category>
    </item>
    <item>
      <title>News Feed System Design With Photo Sharing and Carousel - Deep Dive. (Part 1)</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Mon, 23 Nov 2026 19:45:26 +0000</pubDate>
      <link>https://dev.to/gvegacl/news-feed-system-design-with-photo-sharing-and-carousel-deep-dive-part-1-mgc</link>
      <guid>https://dev.to/gvegacl/news-feed-system-design-with-photo-sharing-and-carousel-deep-dive-part-1-mgc</guid>
      <description>&lt;p&gt;Designing a news feed is a classic front-end system design question. Many guides focus on single pieces of the system or give high-level overviews without diving into the mechanics of any of them.&lt;/p&gt;

&lt;p&gt;This makes sense for a 45-minute interview where you can't explain everything, so guides stick to a broad overview and assume you will not have time to dive deeply into most subsystems.&lt;/p&gt;

&lt;p&gt;My goal for this article series is to build a fleshed-out system diagram that includes all (or almost all) elements in a news feed so we avoid any "black boxes" in our design.&lt;/p&gt;

&lt;h1&gt;
  
  
  Requirements
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Functional Requirements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Users can browse an infinite feed of posts.

&lt;ul&gt;
&lt;li&gt;Users can scroll continuously to load older posts and refresh stale sessions without losing their current reading position or duplicating already-loaded posts.&lt;/li&gt;
&lt;li&gt;A failed pagination request displays an inline retry option at the bottom of the feed while keeping all already-loaded posts interactive and visible.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Users can follow and unfollow people (unfollowing or unfriending immediately removes that person's private posts from the active feed and client cache).&lt;/li&gt;
&lt;li&gt;Users can block other users.&lt;/li&gt;
&lt;li&gt;Users can mute other users.&lt;/li&gt;
&lt;li&gt;Users can react to posts.&lt;/li&gt;
&lt;li&gt;Users can create new posts.

&lt;ul&gt;
&lt;li&gt;Posts can contain multiple pictures.&lt;/li&gt;
&lt;li&gt;Posts can contain an optional title, description, hashtags, and mentions.&lt;/li&gt;
&lt;li&gt;Post editing and creation use a WYSIWYG (What You See Is What You Get) editor.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Users can edit pictures in a live WYSIWYG preview before posting:

&lt;ul&gt;
&lt;li&gt;Filters.&lt;/li&gt;
&lt;li&gt;Cropping.&lt;/li&gt;
&lt;li&gt;Adding text and stickers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Posts with multiple pictures render as an interactive carousel:

&lt;ul&gt;
&lt;li&gt;Mobile users swipe horizontally to move between pictures.&lt;/li&gt;
&lt;li&gt;Desktop users click Prev/Next arrows (or press Left/Right arrow keys) to move between pictures.&lt;/li&gt;
&lt;li&gt;The carousel displays a slide counter (e.g., &lt;code&gt;2 / 5&lt;/code&gt;) and stops at the first and last slide without looping.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Posts and photos can be "private" or "public." Private photos are shown only to the author's friends; public photos are shown to everyone.&lt;/li&gt;
&lt;li&gt;Users can edit posts, and an "edited" badge will be shown on the post.&lt;/li&gt;
&lt;li&gt;Users can share or "repost" posts.&lt;/li&gt;
&lt;li&gt;Users can comment on posts.

&lt;ul&gt;
&lt;li&gt;Comments support mentions and hashtags in a WYSIWYG editor.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Users can click a post to open its post-detail view.&lt;/li&gt;
&lt;li&gt;When the app wakes from sleep, or the user returns to a backgrounded tab, the feed shows a "New posts available" banner instead of prepending posts and shifting what the user is reading.&lt;/li&gt;
&lt;li&gt;Users can sort the feed by "hot/ranked" order or chronological order.&lt;/li&gt;
&lt;li&gt;Ads appear roughly every 5 posts.&lt;/li&gt;
&lt;li&gt;Users can keep the feed open in two browser tabs at the same time without state conflicts or stale reactions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Non-functional Requirements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Crawlability:&lt;/strong&gt; Public post permalinks and public profiles must be crawlable by search engines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cold Load Speed:&lt;/strong&gt; The initial feed must render in under 2.5s at p75 (75th percentile) on a mid-range 4G mobile device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrent Editing &amp;amp; Uploading:&lt;/strong&gt; Users can upload edited photos in the background while continuing to edit other slides or draft their caption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Warm Navigation Speed:&lt;/strong&gt; Returning to the feed from a single-post view must render in under 100 ms from client cache without losing scroll position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero Cumulative Layout Shift (CLS &amp;lt; 0.1):&lt;/strong&gt; Reserved aspect-ratio boxes prevent the feed from jumping as images load or as users switch carousel slides.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bounded Client Memory &amp;amp; DOM Size:&lt;/strong&gt; Active DOM nodes stay under 1,500 via list virtualization, and total tab RAM stays under 200 MB on mobile by decoding only the active and adjacent carousel slides (&lt;code&gt;current - 1&lt;/code&gt;, &lt;code&gt;current&lt;/code&gt;, &lt;code&gt;current + 1&lt;/code&gt;) and capping the in-memory store window.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Privacy &amp;amp; Cache Isolation:&lt;/strong&gt; Private media uses short-lived signed URLs or cookie-gated edge checks, and account-scoped client caches (IndexedDB, Service Worker, memory store) purge immediately on logout or account switch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Main-Thread Responsiveness (INP &amp;lt; 200 ms):&lt;/strong&gt; Client-side image edits, feed scrolling, and reactions respond in under 200 ms (Interaction to Next Paint).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilient Reads/Writes &amp;amp; Bandwidth Adaptation:&lt;/strong&gt; Mutating requests use idempotency keys, pagination retries recover from expired feed generations or transient network errors without discarding already-loaded posts, and images serve responsive &lt;code&gt;AVIF&lt;/code&gt;/&lt;code&gt;WebP&lt;/code&gt; variants matched to viewport and network speed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instant Adjacent Slide Transitions (&amp;lt; 100 ms):&lt;/strong&gt; Intent-based prefetching loads &lt;code&gt;current + 1&lt;/code&gt; and &lt;code&gt;current - 1&lt;/code&gt; slides ahead of navigation so adjacent carousel transitions render in under 100 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EXIF Metadata Stripping:&lt;/strong&gt; The client strips camera EXIF metadata (GPS coordinates, device serials) before upload, and the server re-encodes and verifies every binary before publishing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility (a11y) &amp;amp; Internationalization (i18n):&lt;/strong&gt; The feed, composer, and carousel support keyboard navigation, screen-reader semantics, &lt;code&gt;prefers-reduced-motion&lt;/code&gt;, 44 x 44 px mobile tap targets, and RTL layout mirroring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe Rich-Text Rendering:&lt;/strong&gt; Post and comment bodies store normalized plaintext plus entity ranges rather than raw HTML, neutralizing XSS vectors at render time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Architecture choices
&lt;/h1&gt;

&lt;p&gt;Before diving into each feature, we need to lock down our architectural choices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database - SQL vs NoSQL
&lt;/h2&gt;

&lt;p&gt;To choose the best database for our system, we should first look at the shape of the data each requirement needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Infinite Scroll (Functional)
&lt;/h3&gt;

&lt;p&gt;Let's start with the app's core functionality: infinite scroll. The cornerstone of the infinite scroll is the Post, so let's figure out what information a post needs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Post
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;An ID so we can find it quickly and link it wherever it needs to go.&lt;/li&gt;
&lt;li&gt;An author ID so we know who made it.&lt;/li&gt;
&lt;li&gt;A body, a title, and community tags.&lt;/li&gt;
&lt;li&gt;Media IDs.&lt;/li&gt;
&lt;li&gt;Engagement metrics.&lt;/li&gt;
&lt;li&gt;Creation timestamp.&lt;/li&gt;
&lt;li&gt;Public/Private indicator.&lt;/li&gt;
&lt;li&gt;Edited indicator.&lt;/li&gt;
&lt;li&gt;Viewer-specific flags (&lt;code&gt;viewerReaction&lt;/code&gt; and &lt;code&gt;viewerHasShared&lt;/code&gt;) — note that these do not live in the &lt;code&gt;posts&lt;/code&gt; table; instead, the server builds them on the fly for the authenticated viewer by joining against &lt;code&gt;post_reactions&lt;/code&gt; and &lt;code&gt;post_shares&lt;/code&gt; at read time.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PostBody&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;communityTags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;mediaIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;engagementMetrics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;EngagementMetrics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isPublic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isEdited&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;viewerReaction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ReactionType&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;viewerHasShared&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;ReactionType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'like'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'love'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'lol'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'wow'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'sad'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'angry'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;EngagementMetrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;reactions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ReactionType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;totalReactions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;commentCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;shareCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Entity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'mention'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'hashtag'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'link'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PostBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// UTF-16 code-unit offsets into NFC-normalized text.&lt;/span&gt;
  &lt;span class="n"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PostReaction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;reactionType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ReactionType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PostShare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PostTag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;tagId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;postCreatedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Given these schemas, what is the best database choice for posts?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Many system design guides default to NoSQL (such as DynamoDB or Cassandra) for posts because social feeds take heavy write volume and partition cleanly by &lt;code&gt;postId&lt;/code&gt;. In a document or wide-column store, writing a new post spreads evenly across shards, and fetching a single post by &lt;code&gt;id&lt;/code&gt; pulls the entire record—including &lt;code&gt;body.entities&lt;/code&gt; and &lt;code&gt;mediaIds&lt;/code&gt; off the disk in one lookup without joining tables. But NoSQL starts fighting us if we go deeper:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User reactions and shares&lt;/strong&gt;:&lt;br&gt;
NoSQL is a no-go here because, without relational joins, it forces us to add reacting userId arrays inside the Post document, which will blow past NoSQL per-item or per-document limits (400 KB per item in DynamoDB or 16MB per document in MongoDB) when posts go viral with thousands of reactions (And their respective user IDs).&lt;br&gt;
We can use relational databases instead: Place a Primary key (userId, postId) on post reactions and post shares, so hydrating posts in a feed takes a single index-only scan (WHERE user_id = $viewerId AND post_id = ANY($postIds)).&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/svpt2m" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual-sort feeds (hot/ranked vs. chronological) and PostTag filtering&lt;/strong&gt;: &lt;br&gt;
For NoSQL, we would need three separate tables to store all feed types (chronological, ranked, community tag feeds). And that would mean running writes on each table whenever a user edits a post. SQL (PostgreSQL) uses B-tree indexes  (created_at DESC, id DESC) and (rank_score DESC, id DESC) on posts, plus PRIMARY KEY (tag_id, post_created_at, post_id) on post_tags for O(log N) scans.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/djj2qf" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immediate privacy, block, and mute enforcement&lt;/strong&gt;:&lt;br&gt;
Private posts must disappear immediately when a viewer unfollows, blocks, or mutes someone. PostgreSQL can check &lt;code&gt;is_public&lt;/code&gt; in the follows and blocks tables in one ACID read, so there's no lag in hiding private posts.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/lvs5f3" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idempotent retries&lt;/strong&gt;: &lt;br&gt;
A composite PRIMARY KEY (user_id, post_id) rejects or upserts duplicate reaction retries atomically at the storage engine without extra distributed locks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL is the right choice for our app's infinite scroll feed.&lt;/strong&gt;&lt;br&gt;
SQL joins are great for our use case, and B-tree indexing lets us fetch data nearly as fast as NoSQL, even at massive scale. &lt;/p&gt;

&lt;p&gt;There's one hardware bottleneck we need to address, though: PostgreSQL uses Multi-Version Concurrency Control (MVCC), so every reaction count update (&lt;code&gt;UPDATE posts SET total_reactions = total_reactions + 1&lt;/code&gt;) writes a new row to the disk (and marks the old row dead for VACUUM), appends to the Write-Ahead Log (WAL), and holds an exclusive row-level lock until commit. In a viral post, concurrent updates queue behind that single row lock and spike p99 latency.&lt;/p&gt;

&lt;p&gt;To solve this, we keep PostgreSQL as the durable source of truth while buffering engagementMetrics increments in Redis (HINCRBY post:counts:{postId} like 1 in RAM) and flushing batched deltas back to PostgreSQL every few seconds.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/kk2694" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The Post type is only one piece of the puzzle. There are many more fields to consider, like the feed, the user, the media, and the ads. Let's move on to the feed itself. What fields should our Feed type have?&lt;/p&gt;

&lt;h4&gt;
  
  
  Feed
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Post IDs.&lt;/li&gt;
&lt;li&gt;ranking ID - This field exists because we want to be aware of re-rankings; when a ranking changes, the client sees an ID mismatch and does a clean refresh instead of duplicating posts.&lt;/li&gt;
&lt;li&gt;cursors: olderCursor and newerCursor - We need these to figure out where the user is on the feed so we can load new posts without duplicate posts.&lt;/li&gt;
&lt;li&gt;older/newer post indicators 

&lt;ul&gt;
&lt;li&gt;hasOlder tells the IntersectionObserver whether older posts still exist past olderCursor; without this indicator, olderCursor === null can be ambiguous. We can't tell whether the feed hasn't loaded yet or if we have hit the oldest post in our DB/feed. We can display a "End of feed" status when hasOlder is false.&lt;/li&gt;
&lt;li&gt;hasNewer tells the UI if fresh posts exist above newerCursor after a background check or tab refocus. We display a "New posts available" banner if hasNewer is true.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;lastFetchedAt.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Feed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FeedSort&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;generation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;postIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;olderCursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;newerCursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;hasOlder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;hasNewer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;lastFetchedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;FeedSort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ranked'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'chronological'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Considering these schemas, should we use SQL or NoSQL?&lt;/strong&gt; &lt;br&gt;
We should consider SQL's weaknesses for this schema. If we compute the feed directly from PostgreSQL on every scroll (pull at read time), the database has to join posts, follows, blocks, and mutes, filter out private posts, and sort the results.&lt;/p&gt;

&lt;p&gt;This isn't scalable; it might work for a user who follows few people, but it will eat too much compute power once users expand their networks. Plus, &lt;code&gt;generation&lt;/code&gt;, &lt;code&gt;olderCursor&lt;/code&gt;, and &lt;code&gt;newerCursor&lt;/code&gt; are transient state, so writing cursor or generation updates to PostgreSQL generates unnecessary Write-Ahead Log (WAL) traffic and MVCC row churn.&lt;/p&gt;

&lt;p&gt;Now let's think about NoSQL:&lt;br&gt;
A NoSQL store (e.g., Cassandra or DynamoDB) solves the disk-seek bottleneck by pre-grouping each user's timeline into a single contiguous partition on disk.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partition Key: &lt;code&gt;(user_id, sort)&lt;/code&gt; — for example, &lt;code&gt;user_42:ranked or user_42:chronological&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Clustering / Sort Key: &lt;code&gt;(rank_score DESC, post_id DESC)&lt;/code&gt; or &lt;code&gt;(created_at DESC, post_id DESC)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cassandra and DynamoDB store partitions inside immutable SSTables (Sorted String Tables) on disk. Because all of user_42's feed entries sit sorted together inside one partition, fetching 20 &lt;code&gt;postIds&lt;/code&gt; past &lt;code&gt;olderCursor&lt;/code&gt; is a single sequential slice on disk.&lt;/p&gt;

&lt;p&gt;Or we could use MongoDB, which can store one Feed document per (user_id, sort) containing &lt;code&gt;generation&lt;/code&gt;, &lt;code&gt;olderCursor&lt;/code&gt;, &lt;code&gt;newerCursor&lt;/code&gt;, and a postIds: [...] array, letting the server read the entire feed in a single primary-key lookup.&lt;/p&gt;

&lt;p&gt;But NoSQL has a problem. We want to use a rank score for our feeds, and background rankers periodically recalculate rank_score and bump the feed's generation ID.&lt;/p&gt;

&lt;p&gt;In an LSM-tree (Log-Structured Merge-tree) engine (Cassandra or DynamoDB), rows on disk are immutable. We can't update a clustering key (rank_score) in place. So on every update, the database must write a tombstone (a deletion marker) at the old position and insert a new entry at the new position.&lt;/p&gt;

&lt;p&gt;So every batch re-rank injects hundreds of tombstones into active user partitions. And those tombstones stay on disk until background compaction merges the SSTables, so when a user scrolls through a heavily re-ranked feed, the p99 latency spikes because the storage engine has to read and skip past dead tombstones on disk before finding 20 live postIds.&lt;/p&gt;

&lt;p&gt;In an architecture like MongoDB, it isn't that different - If you embed postIds inside a single Feed document, appending a new postId every time one of 1,000 followed authors publishes a post forces MongoDB's storage engine (WiredTiger) to rewrite the document and update its B-tree indexes repeatedly. Concurrent writes to the same user's feed document contend for document-level locks and generate heavy disk I/O to push an 16-byte ID.&lt;/p&gt;

&lt;p&gt;So what can we do? In this case, we have two choices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use NoSQL on disk knowing the limitations.&lt;/li&gt;
&lt;li&gt;Go for the "costlier" third option, REDIS.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;WHY REDIS WINS.&lt;br&gt;
Redis lives in RAM, making it much faster, though costlier; it's worth it for us since Feed is the first thing users see and a core functionality we can't afford to throttle.&lt;/p&gt;

&lt;p&gt;Redis has the following advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In-place score updates without tombstones: Running &lt;code&gt;ZADD&lt;/code&gt; updates a post's position inside the in-memory skip list directly. No "tombstones" or "compaction" lag.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sub-millisecond slices &amp;amp; &lt;code&gt;hasNewer&lt;/code&gt; counts: &lt;code&gt;ZREVRANGEBYSCORE&lt;/code&gt; slices &lt;code&gt;postIds&lt;/code&gt; past &lt;code&gt;olderCursor&lt;/code&gt;, and &lt;code&gt;ZCOUNT&lt;/code&gt; checks &lt;code&gt;hasNewer&lt;/code&gt; in microseconds in RAM without touching disk IOPS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic size caps: &lt;code&gt;ZREMRANGEBYRANK&lt;/code&gt; trims each user's timeline to the newest 500–1,000 postIds (~64 KB per user), keeping RAM bounded. At the same time, PostgreSQL stays the durable fallback whenever an inactive user's Redis timeline expires.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I mentioned something in the last point: a PostgreSQL fallback; we must have a durable database as a fallback when using Redis, in this case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Filters for post privacy before showing it to the viewer: If a Viewer blocks or unfollows an Author. The Author's postIds might still sit inside the Viewer's Redis ZSET until an async cleanup job scrubs them. Because the API still hydrates those 20 postIds from PostgreSQL (WHERE id = ANY($postIds)), PostgreSQL's ACID check against follows, blocks, and is_public acts as the final gatekeeper and drops unauthorized posts before building the JSON payload.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cache eviction for inactive users: Redis keeps hot timelines in RAM with a TTL (e.g., 7–14 days). When an inactive user returns after a month and hits a cache miss, the server runs the fallback SQL query on PostgreSQL, repopulates their Redis ZSET, and serves the feed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Celebrity fan-out spikes: When an author with 5 million followers publishes a post, pushing that postId into 5 million Redis &lt;code&gt;ZSETs&lt;/code&gt; saturates network bandwidth and Redis's single-threaded event loop (We'll talk about how to fix this when we talk about Feed Generation - Fan-Out on Write vs. Fan-Out on Read).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/64gc4t" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Next, we need to think about the user field.&lt;/p&gt;

&lt;h4&gt;
  
  
  User
&lt;/h4&gt;

&lt;p&gt;Let's ponder which fields belong in the user type&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;user ID&lt;/li&gt;
&lt;li&gt;name&lt;/li&gt;
&lt;li&gt;handle&lt;/li&gt;
&lt;li&gt;profile picture URL&lt;/li&gt;
&lt;li&gt;Relationship to viewer - This is assembled on the fly for the authenticated viewer.

&lt;ul&gt;
&lt;li&gt;Relationship to viewer will include: &lt;/li&gt;
&lt;li&gt;friend&lt;/li&gt;
&lt;li&gt;following&lt;/li&gt;
&lt;li&gt;muted&lt;/li&gt;
&lt;li&gt;blocked
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;RelationshipToViewer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;isFriend&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isFollowing&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isMuted&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isBlocked&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;profilePhotoUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;relationshipToViewer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RelationshipToViewer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Built at read time for the viewer&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;FollowEdge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;followerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;followeeId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isFriend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;BlockEdge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;blockerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;blockedId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;MuteEdge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;muterId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;mutedId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NoSQL might seem like a good fit for User profiles. Each User record is a small JSON object keyed by id, but our relationshipToViewer, block, and mute requirements make NoSQL have problems:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why NoSQL struggles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document stores (MongoDB / DynamoDB) break on embedded edge lists: If you store &lt;code&gt;followingIds&lt;/code&gt;, &lt;code&gt;blockedIds&lt;/code&gt;, or &lt;code&gt;friendIds&lt;/code&gt; as arrays inside the User document, an active user who follows or mutes thousands of accounts bloats the document, triggers write contention on every follow/unfollow, and forces the application server to download and scan entire arrays to check the 15 unique authors on a single feed page.&lt;/li&gt;
&lt;li&gt;Wide-column stores (Cassandra / DynamoDB) force duplicate edge tables: Social edges need two query directions:

&lt;ul&gt;
&lt;li&gt;Forward check (Feed hydration): Given &lt;code&gt;viewerId&lt;/code&gt; and the 15 &lt;code&gt;authorIds&lt;/code&gt; on the current feed page, return &lt;code&gt;isFollowing&lt;/code&gt;, &lt;code&gt;isFriend&lt;/code&gt;, &lt;code&gt;isMuted&lt;/code&gt;, and &lt;code&gt;isBlocked&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reverse check (Fan-out): Given &lt;code&gt;authorId&lt;/code&gt;, fetch all &lt;code&gt;followerIds&lt;/code&gt; when that author publishes a new post.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a wide-column store without secondary indexes or joins, serving both directions forces us to maintain two separate tables (&lt;code&gt;user_following&lt;/code&gt; partitioned by &lt;code&gt;viewerId&lt;/code&gt; and &lt;code&gt;user_followers&lt;/code&gt; partitioned by &lt;code&gt;followeeId&lt;/code&gt;) and write retry/reconciliation jobs so a follow never succeeds in one table while failing in the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about Graph Databases?&lt;/strong&gt; &lt;br&gt;
Graph databases (Neo4j / Amazon Neptune) add cross-database lag: Graph databases are excellent for 3-to-4-hop traversals that a news feed doesn't need on every scroll (e.g., "friends of friends of friends"). Our feed only checks 1-hop edges (viewer -&amp;gt; author), so putting social edges in a separate graph database splits the source of truth. When Viewer A blocks or unfriends Author B, you have to synchronize that change from Neo4j to PostgreSQL before &lt;code&gt;isPublic: false&lt;/code&gt; posts stop leaking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why SQL (PostgreSQL) Wins for User and Social Edges&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Atomic uniqueness on identity fields: PostgreSQL enforces unique constraints on handle and email addresses at the storage level. (Two concurrent sign-ups can never claim the same handle.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bidirectional B-tree indexes without duplicating rows: On follows, putting &lt;code&gt;PRIMARY KEY (follower_id, followee_id)&lt;/code&gt; alongside a secondary index &lt;code&gt;(followee_id, follower_id)&lt;/code&gt; lets one table serve both feed hydration and reverse follower lookups. When hydrating a 20-post feed page, PostgreSQL runs an index-only scan &lt;code&gt;(WHERE follower_id = $1 AND followee_id = ANY($2))&lt;/code&gt;, checking its lightweight Visibility Map in RAM to return the edge flags straight from the B-tree leaf pages without even reading the main table heap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Immediate ACID enforcement on blocks and unfollows: Because users, follows, blocks, mutes, and posts sit in the same PostgreSQL database, blocking or unfriending someone commits in a single ACID transaction. The next feed read sees the updated edge immediately. (Blocked users get blocked instantly)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Where Redis Assists (Caching Static Profile Fields)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is one read-amplification hotspot on User: in a 20-post feed, millions of users fetch the same viral creators' static profile fields (name, handle, profilePhotoUrl) on every scroll. Even though WHERE id = ANY($1) is a fast primary-key lookup, hammering PostgreSQL for unchanged avatars and display names wastes database CPU.&lt;/p&gt;

&lt;p&gt;The clean split is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redis (Profile Cache): Cache public profile fields (name, handle, profilePhotoUrl) in Redis (MGET user:profile:{id} with a TTL and explicit invalidation whenever a user updates their profile).&lt;/li&gt;
&lt;li&gt;PostgreSQL (Store + Edges): Keep users, follows, blocks, and mutes in PostgreSQL so relationshipToViewer is always computed from fresh, transactional edge indexes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/9mm3k6" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We are almost done with our fields; let's now think about how media is stored.&lt;/p&gt;

&lt;h4&gt;
  
  
  Media
&lt;/h4&gt;

&lt;p&gt;Posts reference &lt;code&gt;mediaIds: string[]&lt;/code&gt;, so the feed needs a Media structure for single images and multi-slide carousels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Media ID&lt;/li&gt;
&lt;li&gt;source&lt;/li&gt;
&lt;li&gt;srcSetAvif and srcSetWebp - These are image formats to let the browser pick a variant depending on internet bandwidth and screen size (e.g., mobile 4G vs. desktop screens) &lt;/li&gt;
&lt;li&gt;placeholder - A simple BlurHash or ThumbHash of about 25 bytes.&lt;/li&gt;
&lt;li&gt;Alt text string.&lt;/li&gt;
&lt;li&gt;width and height - To let the frontend pre-render sizes and prevent CLS - it also allows for faster rendering since the browser can ask for the optimal picture size up-front.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;MediaStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'processing'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'ready'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'failed'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;MediaRecord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;ownerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// Verifies the uploader owns this mediaId before attaching to a post&lt;/span&gt;
  &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Null while uploading in the composer before the user hits Publish&lt;/span&gt;
  &lt;span class="n"&gt;storageKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// Internal S3/R2 object path (used to mint signed URLs at read time)&lt;/span&gt;
  &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isPublic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MediaStatus&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each image still needs a ~200-byte metadata row (id, ownerId, postId, width, height, placeholder, storageKey, isPublic, status).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NoSQL pros&lt;/strong&gt;: &lt;br&gt;
Hydrating media for a feed page is a straightforward key lookup (WHERE id = ANY($mediaIds)), and embedding width, height, and placeholder inside a NoSQL Post document avoids a separate lookup at read time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NoSQL cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Atomic ownership checks during concurrent uploads (preventing IDOR): Our requirements let users upload photos in the background while drafting their caption. When the user clicks Publish (POST /posts with mediaIds: ['m1', 'm2']), the backend must verify in one atomic step that m1 and m2 belong to ownerId (stopping an attacker from attaching another user's private mediaId to a public post), that both have finished transcoding (status === 'ready'), and that neither is already attached to another post—then set postId and isPublic inside the same ACID transaction that inserts the posts row.&lt;/li&gt;
&lt;li&gt;Single-transaction privacy updates: When an author edits a post from public to private (or private to public), PostgreSQL updates posts.is_public and media.is_public together in one transaction. In a NoSQL store without multi-document transactions, a partial write leaves a private post serving public CDN URLs.&lt;/li&gt;
&lt;li&gt;Fast orphan cleanup: Users frequently upload photos in the composer and close the tab without publishing. A partial B-tree index on media (created_at) WHERE post_id IS NULL lets a background worker find abandoned uploads older than 24 hours in milliseconds and delete their S3/R2 objects without scanning active media rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;SQL pros&lt;/strong&gt;&lt;br&gt;
SQL allows us to keep width, height, and placeholder in PostgreSQL, letting GET /feed return aspect ratios and 25-byte placeholders in a single batched query (WHERE id = ANY($mediaIds)), keeping Cumulative Layout Shift (CLS &amp;lt; 0.1) near zero without touching object storage on feed reads.&lt;/p&gt;

&lt;p&gt;So we should use SQL.&lt;/p&gt;
&lt;h4&gt;
  
  
  Media BLOBs
&lt;/h4&gt;

&lt;p&gt;We need to store the actual media somewhere. The best practice for this is using blob storage; We have a few options that depend on the image's access patterns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CDNs - To keep popular images geographically close to where they are needed and quickly accessible.&lt;/li&gt;
&lt;li&gt;Blob storage (e.g. Amazon S3, Cloudflare R2) - To store the bulk of our images&lt;/li&gt;
&lt;li&gt;Cold storage (e.g., Amazon Glacier) - To store rarely accessed data and for archival purposes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/s7jxyj" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  AdItem
&lt;/h4&gt;

&lt;p&gt;Keep sponsored cards separate from user posts so ad campaign fields never pollute the posts table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;AdItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;campaignId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;sponsorName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;sponsorAvatarUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;headline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;ctaLabel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;ctaUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;impressionToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Signed payload sent back when the ad enters the viewport&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Backend database row powering ad selection and billing&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;AdCampaign&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;advertiserId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'active'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'paused'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'exhausted'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;dailyBudgetCents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;spentTodayCents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;cpmCents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Cost per 1,000 impressions&lt;/span&gt;
  &lt;span class="n"&gt;targetTags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SQL should own ad_campaigns, ad_items and billing ledgers&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ACID budget caps: Advertisers pay per thousand impressions (cpmCents) or clicks. If two workers deduct spend from dailyBudgetCents at the same time in an eventually consistent NoSQL store, a campaign can overspend its daily cap before status flips to 'exhausted'. PostgreSQL updates spent_today_cents inside a single transaction (WHERE spent_today_cents + $cost &amp;lt;= daily_budget_cents) and flips status = 'exhausted' once the cap is hit.&lt;/li&gt;
&lt;li&gt;Idempotent billing logs: Every billed view writes an append-only row to ad_billing_events with a UNIQUE constraint on impression_token_id and foreign keys to ad_campaigns and ad_items. If a mobile client retries a dropped POST /ads/impressions call, PostgreSQL rejects the duplicate token so the advertiser never pays twice for one view.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;SQL cons on feed scroll&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Per-viewer frequency capping (seen_ads): Users should not see the same ad every 5 posts as they scroll. Tracking seen campaigns in a PostgreSQL ad_impressions(user_id, campaign_id, seen_at) table and running WHERE c.id NOT IN (SELECT campaign_id FROM ad_impressions WHERE user_id = $viewerId AND seen_at &amp;gt; NOW() - INTERVAL '24 hours') on every page load forces PostgreSQL to scan and write ephemeral session rows at high QPS, bloating B-tree indexes with data that expires the next day.&lt;/li&gt;
&lt;li&gt;MVCC lock contention on hot campaigns: Just like viral Post reactions, running UPDATE ad_campaigns SET spent_today_cents = spent_today_cents + $cost thousands of times per second queues concurrent writes behind a lock on that campaign row and spikes Write-Ahead Log (WAL) traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Luckily, we have already decided that REDIS is the best choice for feeds:&lt;br&gt;
&lt;strong&gt;How Redis Handles the Hot Path&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Frequency capping in Redis (SET with TTL): When the feed assembler picks an ad for viewerId, it records SADD seen_ads:{userId} {campaignId} with a 24-hour EXPIRE. On the next scroll, the server reads SMEMBERS seen_ads:{userId} from RAM in microseconds and filters out already-seen campaigns before selecting the next AdItem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Buffered impression counters: Incoming POST /ads/impressions calls verify the impressionToken signature, deduplicate the token in Redis (SETNX seen_token:{tokenId}), increment HINCRBY campaign:spend:{campaignId} impressions 1, and flush batched spend deltas to PostgreSQL every few seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interleaving at read time instead of fan-out on write: Unlike organic posts, ads never enter a user's pre-computed feed:{userId}:{sort} Redis ZSET. A campaign can pause or exhaust its budget at 2:04 PM; if its ID sat inside 5 million cached user timelines, you would have to scrub millions of ZSETs or leave empty slots in user feeds. Instead, the API slices 20 organic postIds from Redis, hydrates them from PostgreSQL, and inserts an eligible AdItem at every 5th slot right before returning the JSON payload.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/zt3vpq" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Comments
&lt;/h4&gt;

&lt;p&gt;Our final step when deciding NoSQL vs SQL is &lt;code&gt;comments&lt;/code&gt;.&lt;br&gt;
Post and comment are very similar schemas, so just like Post, a comment needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Post and parent links (postId and parentCommentId): Every comment belongs to a post. Keeping parentCommentId: string | null (null for top-level comments, or the top-level comment's ID for 1-level replies) supports threaded replies in the post-detail view without recursive tree queries.&lt;/li&gt;
&lt;li&gt;Edited indicator (isEdited): Matches post editing so users see when a comment changed after posting.&lt;/li&gt;
&lt;li&gt;Viewer-specific reaction flag (viewerHasLiked): Built on the fly at read time from a comment_reactions join table—never stored as a column on comments.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;parentCommentId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// null for top-level comments; parent ID for 1-level replies&lt;/span&gt;
  &lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PostBody&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Reuses normalized plaintext + UTF-16 entity spans&lt;/span&gt;
  &lt;span class="n"&gt;likeCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;replyCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;isEdited&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;viewerHasLiked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Built at read time from comment_reactions&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CommentReaction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;commentId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's think about NoSQL vs SQL for comments, &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NoSQL Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contiguous partition reads in wide-column stores (Cassandra / DynamoDB): Comments are always read inside a single post's detail view. Using postId as the partition key and (created_at ASC, comment_id ASC) as the clustering key stores a post's comments together on disk, so loading the first 30 comments is a single sequential slice.&lt;/li&gt;
&lt;li&gt;Embedding small threads in document stores (MongoDB): When a post only has five comments, embedding them inside the Post document fetches the post and its discussion in one lookup.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NoSQL Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Viral threads break document embedding: Embedding comments inside a Post document collapses the moment a viral post collects 50,000 comments—blowing past MongoDB's 16 MB document limit or DynamoDB's 400 KB item limit and forcing the storage engine to rewrite the entire Post document on every new reply.&lt;/li&gt;
&lt;li&gt;Hot-partition bottlenecks: Partitioning strictly by postId routes every read and write for a viral post to a single storage shard, saturating that node's disk IOPS while other shards sit idle.&lt;/li&gt;
&lt;li&gt;Block filtering and viewer hydration at read time: When a Viewer opens a post-detail view, comments from users the Viewer blocked must be excluded, and each comment needs viewerHasLiked hydrated from comment_reactions. Without joins, a NoSQL store has to fetch raw comments first, run separate queries against blocks and comment_reactions, and filter out blocked comments in application code (shrinking a 30-comment page down to 22 items).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why SQL is better with a Redis Counter Buffer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-range B-tree scans for keyset pagination: Defining a composite B-tree index on (post_id, parent_comment_id, created_at ASC, id ASC) groups all top-level comments (parent_comment_id IS NULL) for a post into one contiguous leaf range ordered by creation time. Paginating with a keyset cursor (WHERE post_id = $1 AND parent_comment_id IS NULL AND (created_at, id) &amp;gt; ($cursorTime, $cursorId) LIMIT 30) walks 30 adjacent keys on the leaf page without slow OFFSET scans.&lt;/li&gt;
&lt;li&gt;ACID block checks, cascades, and idempotency: PostgreSQL filters out blocked authors (NOT EXISTS against blocks), hydrates viewerHasLiked via an index-only scan on comment_reactions (user_id, comment_id), cascades deletions automatically when an author deletes a post (ON DELETE CASCADE), and rejects duplicate mobile retries via a UNIQUE (author_id, idempotency_key) constraint.&lt;/li&gt;
&lt;li&gt;Offloading hot counters to Redis: Just like Post.engagementMetrics, updating posts.comment_count or comments.like_count directly in PostgreSQL during a viral spike creates MVCC dead tuples and row-lock contention. Buffering those increments in Redis (HINCRBY post:counts:{postId} comments 1) and flushing batched deltas to PostgreSQL every few seconds absorbs the write burst in RAM while keeping PostgreSQL as the durable source of truth.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/m9k6k4" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Putting the Storage Layer Together
&lt;/h3&gt;

&lt;p&gt;Matching each schema to its physical access pattern splits our storage across three engines rather than forcing one database to handle conflicting workloads:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt; owns the durable relational tables (&lt;code&gt;posts&lt;/code&gt;, &lt;code&gt;post_reactions&lt;/code&gt;, &lt;code&gt;post_shares&lt;/code&gt;, &lt;code&gt;post_tags&lt;/code&gt;, &lt;code&gt;users&lt;/code&gt;, &lt;code&gt;follows&lt;/code&gt;, &lt;code&gt;blocks&lt;/code&gt;, &lt;code&gt;mutes&lt;/code&gt;, &lt;code&gt;media&lt;/code&gt;, &lt;code&gt;ad_campaigns&lt;/code&gt;, &lt;code&gt;comments&lt;/code&gt;, and &lt;code&gt;comment_reactions&lt;/code&gt;). ACID transactions, composite B-tree indexes, and unique constraints enforce immediate block and privacy checks, idempotent retries, and O(log N) keyset pagination.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis&lt;/strong&gt; handles the in-memory hot paths: pre-computed user timelines (&lt;code&gt;ZSET&lt;/code&gt;), buffered reaction, comment, and ad-impression counters (&lt;code&gt;HINCRBY&lt;/code&gt;), cached public user profiles (&lt;code&gt;MGET&lt;/code&gt;), and 24-hour seen-ad sets (&lt;code&gt;SET&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object Storage (S3 / Cloudflare R2) + CDN&lt;/strong&gt; stores and serves immutable &lt;code&gt;AVIF&lt;/code&gt; and &lt;code&gt;WebP&lt;/code&gt; image files at the edge so multi-megabyte binaries never evict hot index pages from PostgreSQL RAM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we know where every schema lives, we have solved half of the backend puzzle. A user's timeline sits in a Redis &lt;code&gt;ZSET&lt;/code&gt;, and organic posts live in PostgreSQL—but we still need to decide how posts get into those timelines in the first place, especially when an account with 5 million followers publishes a post or when the server injects an &lt;code&gt;AdItem&lt;/code&gt; every 5 posts without breaking cursors.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Part 2&lt;/strong&gt;, we will lock down the remaining architectural choices before writing any UI code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feed Generation (Fan-Out on Write vs. Fan-Out on Read):&lt;/strong&gt; How we populate chronological and ranked timelines, handle celebrity fan-out spikes, and interleave ads every 5 posts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;REST vs. GraphQL:&lt;/strong&gt; Standard cacheable endpoints (&lt;code&gt;GET /feed&lt;/code&gt;, &lt;code&gt;POST /posts&lt;/code&gt;) vs. typed queries with data-driven dependencies (&lt;code&gt;@match&lt;/code&gt;/&lt;code&gt;@module&lt;/code&gt;) for heterogeneous post formats.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSR vs. CSR (and SPA vs. MPA):&lt;/strong&gt; Rendering crawlable public post permalinks while keeping the personalized feed in an SPA for &lt;code&gt;&amp;lt; 100 ms&lt;/code&gt; return navigation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-Time Updates (Short Polling vs. Long Polling vs. SSE vs. WebSockets):&lt;/strong&gt; Pushing "New posts available" banners and live reaction counts without shifting what the user is reading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Media Upload &amp;amp; Variant Pipeline:&lt;/strong&gt; Two-step presigned uploads, client-side EXIF stripping, and pre-computed vs. on-the-fly edge &lt;code&gt;AVIF&lt;/code&gt;/&lt;code&gt;WebP&lt;/code&gt; resizing.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My Capital One Interview experience. - Full-stack staff engineer.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Mon, 16 Nov 2026 16:28:32 +0000</pubDate>
      <link>https://dev.to/gvegacl/my-capital-one-interview-experience-full-stack-staff-engineer-3nao</link>
      <guid>https://dev.to/gvegacl/my-capital-one-interview-experience-full-stack-staff-engineer-3nao</guid>
      <description>&lt;p&gt;My experience with Capital One started with a recruiter call (They found me through LinkedIn - Canada based). The process took about four weeks. The first step was a ~10-minute screening with the recruiter, then a CodeSignal assignment with 4 questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;neighborSum - Pass: +300 points

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://codesignal.com/blog/example-codesignal-questions/" rel="noopener noreferrer"&gt;https://codesignal.com/blog/example-codesignal-questions/&lt;/a&gt; (Question 1: Array Manipulation)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;alternatingSort - Pass: +300 points

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/discuss/post/2083038/codesignal-by-user0536yw-yyht/" rel="noopener noreferrer"&gt;https://leetcode.com/discuss/post/2083038/codesignal-by-user0536yw-yyht/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I didn't even see this problem.&lt;/li&gt;
&lt;li&gt;1D Obstacle Placement &amp;amp; Collision Check -  completed with the brute-force: +100 points 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/block-placement-queries/description/" rel="noopener noreferrer"&gt;https://leetcode.com/problems/block-placement-queries/description/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Total points: 700 points. Enough to pass to the second round.&lt;/p&gt;

&lt;p&gt;The second round was a video call system design interview. The question was, "Design a URL shortener." The interviewer was very professional and gave me the non-functional requirements up front:&lt;br&gt;
URL shortening system&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New system, internal only for internal employees
- Low volume of new URL creation 
- 2000 new URLs within the first 2 days   
- 500 new URLs per day steady state
- 5000 redirects per day, steady from day one
- North America only for MVP implementation
- 50,000 internal users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interviewer made it clear that they wanted me to dive deep into how the short URL would be created, stored, and retrieved. He also asked me to explain my choice of database (SQL vs. NoSQL).&lt;/p&gt;

&lt;p&gt;I didn't pass this interview because I fumbled the short URL creation details: e.g., sequential ID using Redis and then Base 10 ID to Base62. Or a truncated Hash function with collision checking. Plus, I couldn't explain the differences between SQL and NoSQL other than the classic "SQL is for structured data and strong consistency, and NoSQL is for unstructured data and massive scale"&lt;/p&gt;

&lt;p&gt;After the interview, I decided to dive deeper into URL shorteners, and I wrote this &lt;a href="https://dev.to/gvegacl/the-url-shortener-system-design-lie-what-prep-guides-hand-wave-and-what-production-actually-needs-1cka"&gt;article with lessons I read&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;About the author:&lt;br&gt;
I'm a Frontend Senior / Staff engineer. I'm currently exploring new engineering opportunities. connect with me on &lt;a href="https://github.com/g-vega-cl" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or check out my work on &lt;a href="https://github.com/g-vega-cl" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>interview</category>
      <category>webdev</category>
      <category>career</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The URL Shortener System Design Lie: What Prep Guides Hand-Wave (And what production actually needs)</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Wed, 04 Nov 2026 13:17:56 +0000</pubDate>
      <link>https://dev.to/gvegacl/the-url-shortener-system-design-lie-what-prep-guides-hand-wave-and-what-production-actually-needs-1cka</link>
      <guid>https://dev.to/gvegacl/the-url-shortener-system-design-lie-what-prep-guides-hand-wave-and-what-production-actually-needs-1cka</guid>
      <description>&lt;p&gt;Recently I've been reading about system design, and I stumbled upon one of the "easiest" and "most basic" interview questions in system design: "Design A URL Shortener"&lt;/p&gt;

&lt;p&gt;I saw the problem in &lt;a href="https://bytebytego.com/courses/system-design-interview/design-a-url-shortener" rel="noopener noreferrer"&gt;Alex Xu's book&lt;/a&gt;, &lt;a href="https://systemdesign.one/url-shortening-system-design/" rel="noopener noreferrer"&gt;systemDesignOne&lt;/a&gt;, &lt;a href="https://blog.algomaster.io/p/design-a-url-shortener" rel="noopener noreferrer"&gt;algomaster&lt;/a&gt;, &lt;a href="https://www.youtube.com/watch?v=iUU4O1sWtJA" rel="noopener noreferrer"&gt;HelloInterview&lt;/a&gt;, etc... And I noticed that these resources tend to "handwave" a lot of depth, depth that a real interviewer will hone in on because we know many people use buzzwords without understanding the background.&lt;/p&gt;

&lt;h1&gt;
  
  
  The "handwaves"
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. NoSQL vs SQL
&lt;/h2&gt;

&lt;p&gt;Something I consistently saw across these guides is the disregard for explaining why SQL or NoSQL. In some cases, the authors mention it on one line, and that's it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A better option is to store  mapping in a relational database."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Other times, articles use the same substance-less justification:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Given these points, a NoSQL database like DynamoDB or Cassandra is a better option due to their ability to efficiently handle billions of simple key-value lookups and provide high scalability and availability."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I see these consistently:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"As the URL mappings are independent and don't have complex relationships, a NoSQL database is a good fit. MongoDB is a strong candidate because:&lt;br&gt;
It uses a leader-follower protocol, enabling the use of replicas for heavy read workloads.&lt;br&gt;
MongoDB ensures atomicity in concurrent write operations and returns duplicate-key errors to prevent collisions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I know the authors can't cover every topic, and many expect readers to know these concepts already. But this is a recipe for a candidate to stumble the moment someone questions these assumptions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "We'll use NoSQL because it can handle billions of simple key-value lookups"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewer&lt;/strong&gt;: "Can't SQL handle simple key-value lookups?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "Uhhhh, no?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most databases are already quite advanced, so either SQL or NoSQL will work for 99% of projects. For example, a Primary Key lookup in PostgreSQL (&lt;code&gt;SELECT long_url FROM urls WHERE short_code = '2TX';&lt;/code&gt;) traverses a B-Tree index in memory in $O(\log N)$ time (3 to 4 pointer hops), resolving in under 1 millisecond—matching DynamoDB single-digit millisecond latency over TCP. We will also focus on that 1% of projects at massive scale where database choice matters.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/22frg2" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;So I intend to clarify the best database choice in depth for at least 3 scenarios: local scale, national scale, and global scale. And explain what actually matters when picking a database.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Single Point of Failure Crashes.
&lt;/h2&gt;

&lt;p&gt;This is one of my biggest gripes because so many articles say a variation of "We have more than one database so we are good" or "the provider will handle this for us"&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Implement automated failover mechanisms for the API and data store layers to switch to backup servers in case of failure."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Our core components (databases, caches, servers) support replication, which provides high availability and fault tolerance. The unique ID generation process also relies on a replicable database, which prevents a single point of failure."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And never mention this again. Or, even worse, don't mention single points of failure at all. This matters especially on smaller-scale systems: what if a single server or database handles all our traffic? - Which begets more questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;At what size should a new database or server be added?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU saturation, connection limits, and blast radius dictate a new server. In production, scale out compute nodes once sustained CPU exceeds ~70% or active socket connections saturate thread pools. At the same time, databases add read replicas when read latency spikes and scale storage volumes vertically long before horizontal partitioning is ever warranted.&lt;/li&gt;
&lt;li&gt;For example, on Amazon RDS, the cost of CPUs/RAM of the database server is separate from the storage (e.g., SSD); each GB costs about $0.23 USD (Multi-AZ), so for pure data growth you'll find yourself increasing storage capacity rather than server capacity.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Can we get away with two tiny EC2 Amazon instances (&lt;code&gt;t4g.nano&lt;/code&gt;)?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yes, for low-throughput workloads (like a few hundred to thousands of requests daily), two &lt;code&gt;t4g.nano&lt;/code&gt; instances (0.5 GB RAM, 2 vCPUs) sitting across two Availability Zones behind an Application Load Balancer provide real high availability for negligible cost. The constraint on nano instances is not handling the traffic spikes—which burstable credits cover—but keeping the operating system and application memory footprint small enough to avoid Linux Out-Of-Memory (OOM) kills.&lt;/li&gt;
&lt;li&gt;One might confuse compute and storage here and think that having two instances is unnecessary if we are using a managed DB service (e.g., Amazon RDS) for two reasons:&lt;/li&gt;
&lt;li&gt;1. Managed database services already include a "multi-availability zone" option, so it's easy to assume we don't need two compute instances for resilience.&lt;/li&gt;
&lt;li&gt;2. The bulk of an instance's cost is CPU/RAM, not storage—so running multiple instances sounds like wasted money compared to a single instance with more storage capacity.&lt;/li&gt;
&lt;li&gt;But in reality, these are two separate layers: two &lt;code&gt;t4g.nano&lt;/code&gt; EC2 instances across AZs provide high availability for the &lt;strong&gt;stateless compute tier&lt;/strong&gt; (so our web app doesn't go down if one VM reboots), while an RDS Multi-AZ deployment provisions a second standby database instance in another AZ to provide high availability for the &lt;strong&gt;database tier&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Are Amazon instances already crash-resistant?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No, individual EC2 instances are isolated virtual machines that can and do crash, terminate during underlying hardware faults, or lose transient host capacity.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Do Amazon EC2 instances already have memory attached?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every EC2 instance has virtualized RAM allocated by the hypervisor. Still, that memory is strictly volatile—the instant an instance crashes or restarts, all in-memory data is erased, which is why stateful persistence is offloaded to remote network storage (EBS) or managed database engines.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My goal is for readers to understand the nuances behind saying, "Put it all on DynamoDB and let it be."&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/ldgdyf" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  3. How Is the Short URL Actually Made?
&lt;/h2&gt;

&lt;p&gt;So far, I've found three main approaches to shorten the original URL; all are valid, but I've noticed guides skip details of each implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1. The Hash and collision loop.
&lt;/h3&gt;

&lt;p&gt;These look deceptively simple, and most articles have some variation of:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"To resolve hash collisions, we can recursively append a new predefined string until no more collisions are discovered."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"And truncated hashes collide: in 62^7 slots a collision becomes likely somewhere around a few million links, which you will pass on day one. You can check the table and retry, but now every create is a read plus a write, and the retry rate climbs as the table fills."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"If a collision occurs, we append a predefined string or salt to the long URL and hash it again until we find a unique key."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what they omit is details about how hashing works - Imagine this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "We can hash the long URL and get the first seven characters of the hash as our short URL"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewer&lt;/strong&gt;: "How would you prevent collisions between the first seven characters of the hash"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "I would append a predefined string or salt the long URL and hash it again"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewer&lt;/strong&gt;: "Would having a predefined string fix just one collision? What if you get more than two long URLs with the same seven characters? Would you also have to save in the database a list of salts?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "Yes?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The most important things to understand in this pattern are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hashes are non-reversible and are not compression. A cryptographic hash (like MD5 or SHA-256) doesn't compress a 300-character URL; So hashes in this case are just a way of generating a "random" string with alphanumeric characters - it's no different from generating a random string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collisions happen earlier than most people realize; for a seven-character short URL (3.5 TRILLION possible URLs), collisions start happening just after a few million generations (~2.35 million due to the Birthday Paradox).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/ftjptx" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2. The Over-Engineered "Key Generation Service" (KGS)
&lt;/h3&gt;

&lt;p&gt;I don't think anyone in production should use something like this because it's complex and slow. It technically solves collisions, but it introduces a complex system that is hard to scale and manage.&lt;/p&gt;

&lt;p&gt;Defenders of this implementation could argue for its generality, including things like a snowflake/Twitter ID generator. Still, those unique ID generators can't be used for short URLs if we want 7-8 characters because a 64-bit Snowflake ID is 19 digits in decimal, and converting that 64-bit integer to Base62 still requires 11 characters (If this doesn't make a lot of sense, that's okay; it will be explained soon).&lt;/p&gt;

&lt;p&gt;A few examples of this implementation in online guides are:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We can have a standalone Key Generation Service (KGS) that generates random six-letter strings beforehand and stores them in a database (let's call it key-DB). Whenever we want to shorten a URL, we'll take one of the pre-generated keys and use it. This approach makes things simple and fast. We also avoid encoding the URL, and we won't have to worry about duplicates or collisions. KGS will make sure all the keys inserted into key-DB are unique"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And then the same source handwaves the database overhead:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Servers can use KGS to read/mark keys in the database. KGS can use two tables to store keys: one for unused keys, and one for all used keys. As soon as KGS gives keys to a server, it can move them to the used keys table. KGS can keep some keys in memory so it can provide them quickly whenever a server needs them. For simplicity, as soon as KGS loads some keys in memory, it can move them to the used keys table. This ensures each server gets unique keys. If KGS dies before assigning all the loaded keys, it can move them back to the used keys table."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This pattern also adds huge DB overhead by requiring synchronization between databases and continuously inserting, reading with locks, moving, and deleting rows.&lt;/p&gt;

&lt;p&gt;KGS also handwaves the complexity of server crashes (availability) and multiple databases; for example, do we have separate databases for used and unused keys? Are they in the same database? What if one database crashes? How do we decide which database to send the data to then?&lt;/p&gt;

&lt;p&gt;I've noticed candidates gravitate towards this solution when they want to design for large scale but lack specific knowledge of more streamlined patterns, like using Redis counters, which are single-threaded, or relying on MongoDB's internals; therefore, they can generate a count that will always be unique - we'll dive deeper into this later in the article.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3. The Counter + Base62: The Clean Math (And the Handwaved ID Generator)
&lt;/h3&gt;

&lt;p&gt;This is my preferred solution. But I've noticed sites often leave out details that can make or break someone's mental model. Here are a couple of examples:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Its INCR command atomically increments the Counter and returns the new value in a single operation. Because Redis is single-threaded, two simultaneous calls will always receive different values. If one gets 1000, the other gets 1001. This guarantee is what makes Redis ideal for distributed counter management. Each counter value is unique, eliminating the risk of collisions without the need for additional checks."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Challenges: In a distributed environment, maintaining a single global counter can be challenging due to synchronization issues. All instances of our Primary Server would need to agree on the counter value... Sequential counters also produce predictable short codes, making URL enumeration possible. An attacker could iterate through codes to discover all URLs."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the candidate memorizes this information without understanding the background, they will fall into a trap like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash vs Radix: Sometimes candidates think "Base62" is like a hash function, but it is actually a Radix function. Here are the differences between them:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Hash Function (e.g., SHA-256, MD5)&lt;/th&gt;
&lt;th&gt;Base62 (Radix Representation)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;What it is&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A one-way mathematical function mapping variable-sized input to a fixed-size digest.&lt;/td&gt;
&lt;td&gt;A positional base-conversion system using 62 alphanumeric characters (&lt;code&gt;0-9&lt;/code&gt;, &lt;code&gt;a-z&lt;/code&gt;, &lt;code&gt;A-Z&lt;/code&gt;).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Primary Goal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fingerprinting, integrity verification, or pseudo-random distribution.&lt;/td&gt;
&lt;td&gt;High-density positional notation: representing large Base-10 integers using fewer characters.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reversibility&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Irreversible&lt;/strong&gt; (one-way; original input cannot be computed back from the hash digest).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Fully Bijective&lt;/strong&gt; (two-way; can be decoded back to the exact starting integer via modulo/quotient arithmetic).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Collision Risk&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Present&lt;/strong&gt; (different inputs can produce matching digests via the Birthday Paradox).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Zero&lt;/strong&gt; (a unique input integer maps deterministically to a unique Base62 string).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Output Length&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Fixed length&lt;/strong&gt; (e.g., SHA-256 is always 256 bits / 64 hex characters regardless of input length).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Dynamic length&lt;/strong&gt; (proportional to integer size: values $&amp;lt; 62^7$ fit within 7 characters).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Using a single-threaded counter without mentioning coordination when scaling, where the Counter lives, or what happens when your "counter server" crashes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In production, app servers don't call an external counter on every single write. They use &lt;em&gt;dynamic range leases&lt;/em&gt;. It's like fetching a block of 1,000 IDs at a time with &lt;code&gt;INCRBY 1000&lt;/code&gt; from an atomic coordinator (like Redis) and dispensing them locally in memory. If an application server crashes, the remaining IDs in that leased range are abandoned; because a 7-character Base62 namespace has over 3.5 trillion possible values, discarding a few hundred numbers during a crash costs practically nothing and avoids complex recovery locks. Meanwhile, the coordinator survives restarts by replaying its on-disk write-ahead log (such as Redis AOF) or synchronizing across Multi-AZ replicas with a forced offset jump to avoid reissuing duplicate IDs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/qs5sz6" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Security fixes: Many articles mention how using a sequential unique counter creates security issues; yet none show how to fix this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fix is to pass the integer counter through a reversible, collision-free permutation—such as a lightweight Feistel cipher or an obfuscation tool like Sqids/Hashids—before converting to Base62. This scrambles sequential numbers into deterministic, random-looking alphanumeric tokens without risking duplicate keys.&lt;/li&gt;
&lt;li&gt;Remember: The generated short URL doesn't need a direct relationship to the long URL. Your short URL doesn't need to include any information about the long URL; it just needs to be unique.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/v3xsk2" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/965hkc" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Redis Read-through/Write-through/Cache aside
&lt;/h2&gt;

&lt;p&gt;When guides mention Redis, I've noticed many don't distinguish between Read-through/Write-through and cache-aside architectures. This distinction matters when discussing our system's trade-offs. Some examples I've seen:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"1. A user clicks a short URL link: &lt;a href="https://tinyurl.com/zn9edcu" rel="noopener noreferrer"&gt;https://tinyurl.com/zn9edcu&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The load balancer forwards the request to web servers.&lt;/li&gt;
&lt;li&gt;If a short URL is already in the cache, return the long URL directly.&lt;/li&gt;
&lt;li&gt;If a short URL is not in the cache, fetch the long URL from the database. If it is not in the database, the user likely entered an invalid short URL.&lt;/li&gt;
&lt;li&gt;The system returns the long URL to the user.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;The example doesn't even mention whether we're using cache-aside or read-through/write-through architectures. It might describe cache-aside, but it leaves the reader guessing about the details—and notice how Step 4 fetches from the database and Step 5 returns it to the user without ever writing the URL back into the cache!&lt;/p&gt;

&lt;p&gt;Or this other example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"After receiving a request, a web server first checks if the cache has the available response. If it has, it sends data back to the client. If not, it queries the database, stores the response in cache, and sends it back to the client. This caching strategy is called a read-through cache"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This example is misleading; what it describes is actually the definition of &lt;strong&gt;Cache-Aside&lt;/strong&gt;, not Read-Through. In a true &lt;strong&gt;Read-Through&lt;/strong&gt; cache, the application server talks &lt;em&gt;only&lt;/em&gt; to the cache layer. The cache engine itself owns the database driver, connects to PostgreSQL, and transparently pulls the record on a miss. In the real world, almost every production stack uses Cache-Aside because standard Redis has no database drivers or query logic to fetch data from PostgreSQL or DynamoDB on its own. Mislabeling Cache-Aside as Read-Through confuses candidates about who actually owns the database driver and SQL connection pool.&lt;/p&gt;

&lt;p&gt;And:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We can cache URLs that are frequently accessed. We can use some off-the-shelf solution like Memcached, which can store full URLs with their respective hashes. The application servers, before hitting backend storage, can quickly check if the cache has the desired URL."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These examples barely explain how the hardware works or how it fits into our architecture. Are these services (Redis/Memcached) added on their own instance? How are they provisioned? What happens if they crash? Does Redis sit between the server and database as a proxy, or alongside the server as an internal backing service? If the same Redis cluster handles both the read cache (with LRU eviction) and the atomic ID counter (INCR), what stops Redis from evicting your counter key when memory fills up? If Redis crashes, does your Counter reset to zero? - All of these questions will be answered properly when we write our own implementations for three different scales.&lt;/p&gt;

&lt;p&gt;Guides also handwave what happens when you use Redis for counting and caching:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;As an Ephemeral Cache (Reads):&lt;/strong&gt; URLs are cached with an LRU (Least Recently Used) eviction policy to keep hot links in memory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;As an Atomic Counter (Writes):&lt;/strong&gt; Redis executes &lt;code&gt;INCR&lt;/code&gt; or &lt;code&gt;INCRBY&lt;/code&gt; to hand out unique IDs for Base62 encoding.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Another crash could happen if you co-locate both roles on a single Redis instance configured with the standard &lt;code&gt;allkeys-lru&lt;/code&gt; (least recently used) maxmemory policy, because servers lease counter blocks in chunks (e.g., fetching 1,000 IDs at a time). That counter key sits idle between leases. When read traffic surges and Redis memory fills up, Redis's LRU algorithm will see the idle counter key and &lt;strong&gt;evict it from RAM&lt;/strong&gt;. To prevent Redis from evicting the Counter while running, change the configuration from &lt;code&gt;allkeys-lru&lt;/code&gt; to &lt;code&gt;volatile-lru&lt;/code&gt; (under &lt;code&gt;volatile-lru&lt;/code&gt;, Redis evicts only keys with an explicit expiration time, leaving our non-expiring counter key untouched) and/or physically separate the instances. To ensure the Counter doesn't reset to zero if the Redis server crashes and reboots, we need an Append-Only File (AOF) saved to disk or replicated across Availability Zones.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/mgtlqf" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Real sizes (Servers, databases).
&lt;/h2&gt;

&lt;p&gt;System design prep guides frequently create world-scale scenarios, inflate traffic numbers, and jump to massive abstract scales:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Because of the massive scale of billions of records, we must shard our database across multiple database servers using consistent hashing on the short URL."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or even examples like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Since we expect to have 500M new URLs every month and we would like to save this data for 5 years:&lt;br&gt;
Total number of URLs: 500M * 5 years * 12 months = 30 billion&lt;br&gt;
Total storage: 30 billion * 500 bytes = 15 TB"&lt;/p&gt;

&lt;p&gt;"To scale out our DB, we need to partition it so that it can store information about billions of URLs. We need to come up with a partitioning scheme that would divide and store our data into different DB servers."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These examples usually defend themselves by saying, "The cloud will handle it." Still, it's important to know how much servers actually cost, how much capacity they have, and how they differ.&lt;/p&gt;

&lt;p&gt;For instance, some guides calculate 15 TB for 30 billion URLs and claim we must partition across different DB servers. But in real-world infrastructure, a single standard AWS RDS PostgreSQL instance can attach up to 64 TB of storage on a single volume, and an Amazon Aurora cluster scales up to 128 TB automatically without sharding. 15 TB easily fits inside a single managed instance. At the same time, relying on a standalone, un-replicated database instance on a single server without synchronous replication or automated failover remains a catastrophic Single Point of Failure.&lt;/p&gt;

&lt;p&gt;Or what if you need a small, internal system? A single &lt;code&gt;db.t4g.micro&lt;/code&gt; instance (with 1 GB of RAM and a baseline 20 GB gp3 SSD) and a &lt;code&gt;t4g.nano&lt;/code&gt; server are more than enough, yet if that DB or server crashes, your whole system has multiple single points of failure. Imagine a scenario like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "So one single instance would be enough for this small-scale operation"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewer&lt;/strong&gt;: "So how would you handle redundancy? What would happen if that instance fails?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interviewee&lt;/strong&gt;: "The cloud will handle it?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Many guides also gloss over provisioning. When we provision a managed cloud database like AWS RDS (&lt;code&gt;db.t4g.micro&lt;/code&gt;), we're renting an isolated virtual machine. If we run it as a Single-AZ (Availability Zone) instance, we still have a Single Point of Failure, so to make it resilient, we need to enable Multi-AZ (which provisions a synchronous hot standby in a different data center that automatically takes over if the primary dies). The problem is that guides often overlook the internals of this mechanism, and candidates often treat it as a magic phrase without realizing it solves failover resiliency, not write-throughput scaling.&lt;/p&gt;

&lt;p&gt;Candidates often have warped mental models about the physical reality of the servers. For example, Redis persistence doesn't work the same across bare metal and cloud providers. On a self-hosted Linux machine, Redis logs transactions directly to &lt;code&gt;/var/lib/redis/appendonly.aof&lt;/code&gt; on an attached SSD.&lt;/p&gt;

&lt;p&gt;However, on burstable managed cloud instances like AWS ElastiCache (&lt;code&gt;cache.t4g.micro&lt;/code&gt;), AWS turns off continuous AOF disk logging because constant disk syncing (&lt;code&gt;fsync&lt;/code&gt;) exhausts shared I/O credits and blocks the single-threaded event loop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note: Burstable instances and I/O credits&lt;/strong&gt;&lt;br&gt;
A burstable instance operates on an allowance: you get a modest baseline of CPU capacity (around 10%–20%) when idle, but you accumulate credits that let you burst up to 100% CPU when sudden traffic arrives.&lt;/p&gt;

&lt;p&gt;The issue is that storage operations follow a similar metering model. When you run an Append-Only File (AOF), every URL creation triggers an &lt;code&gt;INCR&lt;/code&gt; command, which forces an &lt;code&gt;fsync()&lt;/code&gt; to physically write those bytes from the operating system's buffer to disk. On a tiny, multi-tenant cloud instance, continuous &lt;code&gt;fsync()&lt;/code&gt; calls burn through your allocated I/O credits almost immediately. Once those credits drain to zero, disk access is throttled, causing writes that usually take under a millisecond to stall for 50–100ms. Because Redis executes all commands on a single thread, waiting on that throttled disk blocks the entire engine—freezing reads, writes, and all incoming network connections.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So instead of writing an on-disk transaction log, managed micro instances rely on network-level durability: the primary node asynchronously streams memory state to a hot replica in a different Availability Zone, while periodic binary snapshots (RDB files) are pushed to durable Amazon S3 storage for disaster recovery.&lt;/p&gt;

&lt;p&gt;Something else I've noticed is that guides tend to handwave about scaling a system progressively. If we are going to need 15 TB or 36 TB of data in 5 years, we shouldn't architect Day 1 for Year 5; we can size this for 12-24 months and then scale upwards if needed.&lt;/p&gt;

&lt;p&gt;I believe it's important to ground QPS/TPS/storage values in real offerings. That way, it's much easier to build a complete mental model.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Load Balancer vs. API Gateway vs. Reverse Proxy
&lt;/h2&gt;

&lt;p&gt;I've noticed that many guides also use Load Balancers, API Gateways, and Reverse Proxies interchangeably. For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The load balancer distributes incoming client requests across multiple servers to prevent any single server from becoming a bottleneck. The load balancer can be configured with routing algorithms such as round-robin, least connections, or IP hash."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While another guide ignores the load balancer completely and shows a diagram like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;[ Client ] ──► [ API Gateway ] ──► [ URL Service ] ──► [ Database ]&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Guides should be clear about this instead of glossing over it. In a real system, we might need both an API Gateway and a load balancer, or just one, depending on our architecture. Much of the confusion comes from these two being bundled together in modern managed offerings—such as cloud ingress controllers (like Azure Application Gateway Ingress Controller or GKE Ingress) that handle external Layer 7 (HTTP/HTTPS) traffic routing, TLS termination, and load balancing in a single layer.&lt;/p&gt;

&lt;p&gt;Even when bundled, an API Gateway and a Load Balancer are not interchangeable. The confusion stems from the fact that &lt;strong&gt;both API Gateways and Load Balancers are reverse proxies&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A Load Balancer&lt;/strong&gt; is a reverse proxy tuned for raw connection throughput and even traffic spreading. It is lightweight and consumes very few resources. Load balancers can also be confusing because they behave differently depending on which network layer they operate at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Layer 4 (Network Load Balancer):&lt;/strong&gt; Looks only at IP packets and TCP/UDP ports. It has no concept of HTTP, meaning it cannot see URL paths, headers, or request lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layer 7 (Application Load Balancer):&lt;/strong&gt; Parses HTTP/HTTPS request lines, headers, cookies, and paths (e.g., routing &lt;code&gt;/api/*&lt;/code&gt; to Target Group A and &lt;code&gt;/*&lt;/code&gt; to Target Group B). However, it stops short of evaluating application-level business policy like JWT auth verification or user-specific rate limits. Because of this path routing, an ALB feels very close to an API Gateway.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;An API Gateway&lt;/strong&gt; is a reverse proxy tuned for Layer 7 application policy (authentication, granular rate limiting, and route rewriting). It uses significantly more computational power to inspect payloads, validate cryptographic tokens, and enforce business rules.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another confusing point is that an API Gateway can technically serve as a Load Balancer. Many API Gateways (such as Kong, Envoy, or NGINX) let you configure upstream load-balancing algorithms like Round Robin or Least Connections across your backend instances.&lt;/p&gt;

&lt;p&gt;To make things more complex, Load Balancers can sit either "before" or "after" an API Gateway depending on how the system is set up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The High-Scale / Kubernetes Setup (Load Balancer BEFORE Gateway):&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run gateway software like Envoy or Kong yourself, you need multiple gateway servers so the gateway itself doesn't crash or become a bottleneck. But how do internet users reach multiple gateway servers? You put a Layer 4 Network Load Balancer (NLB) in front to balance incoming TCP sockets across your gateway fleet.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Standalone Gateway (No External Load Balancer):&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In smaller setups, or when using cloud-managed serverless gateways (like AWS API Gateway), you don't provision a separate load balancer in front of it. AWS API Gateway already has an internal ingress routing fleet built in. You point your custom domain name directly to API Gateway, and it routes requests to your backend microservices or serverless functions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Zero API Gateways (Load Balancer Only):&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are building a simple service that doesn't need API token tiers, client rate limits, or complex route rewrites, an Application Load Balancer (ALB) can terminate TLS (decrypting incoming HTTPS traffic) and use Round Robin to distribute HTTP requests straight to your compute nodes. The backend servers handle authentication and business logic themselves.&lt;/p&gt;

&lt;p&gt;So we can think of these three in an inheritance hierarchy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reverse Proxy:&lt;/strong&gt; Any server that sits between a client and a backend server, intercepting requests and responses so the backend stays hidden from the outside world.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Load Balancer (Reverse Proxy + Distribution):&lt;/strong&gt; A reverse proxy optimized to monitor backend health and spread traffic evenly. A Layer 4 LB inspects only raw TCP packets, while a Layer 7 LB inspects HTTP request lines and paths. Both offer ultra-low latency and consume minimal compute. It can send requests to an API Gateway fleet or directly to backend servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Gateway (Reverse Proxy + Load Balancer + Governance):&lt;/strong&gt; A specialized reverse proxy that does load distribution, but also inspects HTTP headers and payloads to enforce business rules—blocking unauthenticated callers, rejecting spam via token buckets, and rewriting URL paths before application code ever executes. Because it decrypts bearer tokens, parses request bodies, and validates schemas, it uses more compute and can introduce a slight latency penalty. It typically sends requests directly to backend servers, though in complex multi-tier setups it can route through internal load balancers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/8ywptq" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Consistent hashing
&lt;/h2&gt;

&lt;p&gt;Whenever system design articles discuss scaling past a single machine, they mention consistent hashing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Our design is horizontally scalable. The database can be sharded, and we can use consistent hashing to distribute load across both the application and database servers evenly."&lt;/p&gt;

&lt;p&gt;"The additional data store is partitioned using consistent hashing. The partition key is the long URL, so we can quickly find the URL record. A key-value store such as DynamoDB is used as the additional data store."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or fall back on basic modulo arithmetic:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We should also potentially consider sharding the database. We can shard it using some mapping from the URL (for example, the URL's hash code modulo some integer), which will allow us to locate the database which contains this file quickly."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Modulo hashing (&lt;code&gt;hash(key) % N&lt;/code&gt;) is an anti-pattern for dynamic systems (which most systems are): the moment you add or remove a single server, almost 100% of your keys map to entirely different machines, causing data thrashing or thundering herds. Consistent hashing solves this by ensuring that when a node joins or leaves, only a fraction of keys ($K/N$) get remapped.&lt;/p&gt;

&lt;p&gt;The problem is how guides illustrate it: a cosmic 360-degree circle floating in the middle of a whiteboard diagram, with keys and servers casually "mapped onto the ring."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ Application Servers ] ──► ( The Floating Hash Ring ) ──► [ Database Shards ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This abstraction can lead to blind spots when an interviewer digs into the physical implementation:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Where Does the Ring Physically Live?
&lt;/h3&gt;

&lt;p&gt;Candidates often assume the hash ring is a standalone service or a central coordinator machine. But if 50 application servers have to make a network call to a "Hash Ring Coordinator" on every single request, that coordinator becomes a latency bottleneck and a single point of failure.&lt;/p&gt;

&lt;p&gt;In production, there is no ring server. The hash ring is an in-memory data structure (like a &lt;code&gt;TreeMap&amp;lt;Long, Node&amp;gt;&lt;/code&gt;) living directly inside the local process RAM of the server making the routing call to the database.&lt;/p&gt;

&lt;p&gt;When a server needs to route a short URL:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It hashes the key using a fast, non-cryptographic algorithm like MurmurHash3 on its own CPU.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It executes a local binary search in $O(\log N)$ time to find the nearest server pin.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The lookup finishes in under a microsecond with zero network round-trips.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/fnpf8w" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  2. How Do Servers Coordinate Changes?
&lt;/h3&gt;

&lt;p&gt;If every application server keeps its own copy of the ring in local RAM, how do they stay synchronized when a database shard crashes or a new cache node boots up?&lt;/p&gt;

&lt;p&gt;Production architectures solve this through two distinct models:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Centralized Coordination:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In systems using standalone cache pools (like Memcached) or sharded SQL instances, the storage nodes don't talk to each other. Instead, a small, independent cluster of coordinator machines (e.g., &lt;code&gt;t4g.small&lt;/code&gt; instances running &lt;code&gt;etcd&lt;/code&gt;, &lt;code&gt;Consul&lt;/code&gt;, or &lt;code&gt;ZooKeeper&lt;/code&gt;) continuously pings the storage nodes. Application servers keep an open watch listener with this coordinator fleet. When a storage machine drops offline, the coordinator alerts the application servers, which instantly recompute and swap their local in-memory tree pointers to route around the dead node.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Decentralized Gossip:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Distributed databases like Apache Cassandra or Amazon DynamoDB eliminate external coordinator servers. Each database server maintains the hash ring directly in process memory. The database machines continuously ping each other across an internal network port to exchange health updates ("Gossip"). If Database Machine C dies, Database Machines A and B detect the dropped heartbeat, spread the update cluster-wide, and independently adjust their local partition boundaries without needing an external manager.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/cp9yfh" width="100%" height="500" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Can Load Balancers and API Gateways Use Consistent Hashing?
&lt;/h3&gt;

&lt;p&gt;Guides suggest using consistent hashing to "distribute load across both application and database servers." This creates confusion: should our Load Balancers or API Gateways use consistent hashing to distribute requests to stateless backend servers?&lt;/p&gt;

&lt;p&gt;For a stateless URL shortener - absolutely not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An Application Load Balancer's job is fair load distribution. Algorithms like Round Robin or Least Outstanding Requests spread traffic evenly across all web servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If your Load Balancer consistently hashes incoming requests based on the URL path (&lt;code&gt;GET /popular-deal&lt;/code&gt;), 100% of the traffic for that viral link will hammer the same backend server. That node will burn through CPU and crash while the remaining servers sit idle. Because stateless backend nodes read from a shared Redis cache or database cluster anyway, pinning specific URLs to specific app servers creates hot spots with no performance gain.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consistent hashing at the Gateway or Load Balancer tier makes sense only when the upstream servers hold in-memory, non-shared state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Local In-Memory Cache Tiers:&lt;/strong&gt; If backend compute nodes maintain an LRU cache directly inside their own process memory instead of calling an external Redis instance, consistent hashing ensures repeat requests hit the host that already holds the cached data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stateful WebSockets:&lt;/strong&gt; Real-time chat applications (like Discord) use consistent hashing at the gateway to route users to the exact server hosting their active room connection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Layer 4 Packet Balancing (e.g., Google Maglev):&lt;/strong&gt; Specialized edge load balancers use consistent hashing algorithms across router fleets so that network packet routes remain stable even if intermediate proxy boxes restart.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Unless your compute nodes hold local state, consistent hashing belongs on the data-routing clients targeting partitioned caches or database shards, not on the front door distributing traffic across stateless application instances.&lt;/p&gt;

&lt;h1&gt;
  
  
  Next steps
&lt;/h1&gt;

&lt;p&gt;Now that we have seen the many holes that guides tend to have, the next part of this article series will show how to design a URL shortener without leaving out any details. This way, any candidate asked this question will be prepared to go in depth at any point in their interview.&lt;/p&gt;

&lt;h1&gt;
  
  
  FAQ
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Implementation · Will the next article provide concrete code or architecture diagrams?
&lt;/h3&gt;

&lt;p&gt;Yes. Part 2 provides production VPC topologies and runnable code across three distinct tiers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Small Internal MVP (~500 writes/day):&lt;/strong&gt; Multi-AZ PostgreSQL using native &lt;code&gt;BIGINT GENERATED ALWAYS AS IDENTITY&lt;/code&gt; sequences, an Application Load Balancer, and a micro Redis instance for Cache-Aside reads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;National Consumer Scale (~5,000 writes/sec):&lt;/strong&gt; Horizontally autoscaling app clusters, dedicated Redis clusters separating atomic ID range leases from LRU read caches, and read replicas for uncached lookups.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Scale (100M+ writes/day):&lt;/strong&gt; Multi-region edge ingestion, decentralized token leases, and auto-partitioned storage (DynamoDB Global Tables).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Trade-offs · How do I actually defend SQL vs. NoSQL in an interview?
&lt;/h3&gt;

&lt;p&gt;Do not recite the generic textbook claim that "NoSQL is faster for key-value lookups". In memory, a PostgreSQL primary key lookup traverses a B-Tree index in $O(\log N)$ time (3 to 4 pointer hops) and resolves in under 1 millisecond—matching DynamoDB latency over TCP. Base your defense on two concrete physical factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Write Idempotency (Deduplication):&lt;/strong&gt; If shortening an identical long URL twice must return the same short code, SQL guarantees this natively via an atomic &lt;code&gt;UNIQUE&lt;/code&gt; constraint on &lt;code&gt;long_url&lt;/code&gt;. In a NoSQL table partitioned by &lt;code&gt;short_url&lt;/code&gt;, querying by &lt;code&gt;long_url&lt;/code&gt; requires either a catastrophic full-table scan or an asynchronously replicated Global Secondary Index (GSI). Because GSIs are eventually consistent, concurrent writes for the same link create duplicate short codes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single-Writer Ceilings:&lt;/strong&gt; A single properly tuned relational database instance comfortably handles 10,000 to 20,000 indexed inserts per second and up to 64–128 TB of storage. Choose NoSQL (DynamoDB or Cassandra) only when sustained write throughput exceeds what a single primary can physically commit (30,000–50,000+ writes/sec) and you treat every link generation as a blind append without global deduplication.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Failure Handling · What happens during a cloud database failover?
&lt;/h3&gt;

&lt;p&gt;Availability is preserved by isolating failure domains rather than assuming managed cloud services eliminate downtime:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The 30–60s Failover Window:&lt;/strong&gt; If a Multi-AZ primary database crashes, automated DNS failover repoints traffic to the synchronous standby in 30 to 60 seconds. During this window, link &lt;em&gt;creation&lt;/em&gt; (&lt;code&gt;POST /shorten&lt;/code&gt;) fails, but link &lt;em&gt;redirects&lt;/em&gt; (&lt;code&gt;GET /{code}&lt;/code&gt;) continue resolving uninterrupted from the Redis Cache-Aside tier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Circuit Breakers:&lt;/strong&gt; Application servers must set aggressive socket timeouts and trip circuit breakers on database calls. If Redis misses a cold link during a database outage, the server must fail fast rather than hanging on dead database TCP connections and exhausting worker thread pools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Counter Recovery:&lt;/strong&gt; Application servers lease blocks of IDs (e.g., &lt;code&gt;INCRBY 1000&lt;/code&gt;) and treat remaining local tokens as ephemeral. If an app server crashes, discard its leased block. Discarding a few hundred IDs out of a 3.5-trillion Base62 namespace costs nothing and avoids complex distributed recovery locks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Security · How do I prevent sequential ID enumeration?
&lt;/h3&gt;

&lt;p&gt;Base62 is a positional base conversion, not encryption—incrementing an integer counter directly leaks predictable URLs (&lt;code&gt;/1&lt;/code&gt;, &lt;code&gt;/2&lt;/code&gt;, &lt;code&gt;/3&lt;/code&gt;) that scrapers can iterate over.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reversible Obfuscation:&lt;/strong&gt; Pass the 64-bit integer through a lightweight, collision-free Feistel cipher or permutation tool (like Sqids/Hashids) before encoding to Base62. This scrambles sequential increments into pseudo-random alphanumeric tokens without risking collisions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edge Rate Limiting &amp;amp; 404 Heuristics:&lt;/strong&gt; Enforce sliding-window rate limits at your API Gateway or reverse proxy (e.g., 60 lookups/min per IP). Track 404-to-200 response ratios at the WAF; clients scanning non-existent short codes will hit abnormal miss ratios and can be automatically blocked at the perimeter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HMAC Signatures for Sensitive Links:&lt;/strong&gt; For private or single-use URLs (such as password resets or invoices), append a cryptographic signature token (&lt;code&gt;/xK9b?sig=...&lt;/code&gt;) validated at the gateway before redirecting.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Scaling · When should I actually shard a database?
&lt;/h3&gt;

&lt;p&gt;Never shard simply because an article mentions "billions of rows". 1 billion URLs at 500 bytes per row is only 500 GB, and 30 billion URLs is 15 TB—both fit comfortably on a single standard 64 TB AWS RDS volume or a 128 TB Aurora cluster without manual partitioning. Shard only when physical single-node thresholds break:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Write IOPS &amp;amp; WAL Flush Limits:&lt;/strong&gt; When sustained write volume breaches ~20,000 to 40,000 writes/sec, where single-primary disk locks and write-ahead log (WAL) syncs become the hardware bottleneck.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Region Latency &amp;amp; Edge Distribution:&lt;/strong&gt; When global users face 150ms+ cross-continental redirect latencies. Resolve this by deploying edge reverse proxies (Cloudflare/CloudFront) and multi-region read replicas (like Aurora Global Database) before attempting cross-region sharding.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  About the author:
&lt;/h3&gt;

&lt;p&gt;I'm a full-stack (frontend-leaning) Senior / Staff engineer. I'm currently exploring new engineering opportunities. If your team is tackling distributed systems challenges or needs someone who designs for production reality instead of interview buzzwords, connect with me on &lt;a href="https://www.linkedin.com/in/cesar-leonardo-vega-galvan/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or check out my work on &lt;a href="https://github.com/g-vega-cl" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>career</category>
      <category>programming</category>
    </item>
    <item>
      <title>Skills, MCPs, and Commands are the same context engineering trend.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Thu, 20 Nov 2025 21:54:01 +0000</pubDate>
      <link>https://dev.to/gvegacl/skills-mcps-and-commands-are-the-same-context-engineering-trend-49dp</link>
      <guid>https://dev.to/gvegacl/skills-mcps-and-commands-are-the-same-context-engineering-trend-49dp</guid>
      <description>&lt;h1&gt;
  
  
  What are skills:
&lt;/h1&gt;

&lt;p&gt;Skills are folders of instructions and scripts that Claude loads to do specialized tasks. &lt;strong&gt;The point of skills is to make Claude follow guidelines and be more deterministic.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;More deterministic&lt;/li&gt;
&lt;li&gt;Easy to edit, share, and set up.&lt;/li&gt;
&lt;li&gt;Efficient context use.*&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Make AI more deterministic.
&lt;/h1&gt;

&lt;p&gt;This is one of the biggest issues with LLMs right now: they spout a lot of code, and they can and will come up with two different approaches and answers to the same prompt. With skills, we add guardrails, instructions, and scripts that tell the LLM exactly what to do. For example, the &lt;code&gt;playwright-skill&lt;/code&gt; I downloaded has a &lt;code&gt;helpers.js&lt;/code&gt; file which has a bunch of scripts like &lt;code&gt;launchBrowser&lt;/code&gt; or &lt;code&gt;safeClick&lt;/code&gt;, so Claude can use those functions and the result will always be the same.&lt;br&gt;
    * This was also a benefit that MCPs had.&lt;/p&gt;
&lt;h1&gt;
  
  
  Easy to edit.
&lt;/h1&gt;

&lt;p&gt;Since Skills are just &lt;code&gt;.md&lt;/code&gt; files and scripts, they are really easy to edit and share if necessary. The downside is that the files can be hard to maintain if they don't have a single source of truth.&lt;/p&gt;
&lt;h1&gt;
  
  
  Context
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Understanding Claude context
&lt;/h2&gt;

&lt;p&gt;Running &lt;code&gt;/context&lt;/code&gt; in Claude code (And in most other CLIs) gives you a breakdown of how context is used in the CLI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp97jaxtc7j1bvj5y8akm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp97jaxtc7j1bvj5y8akm.png" alt=" " width="799" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The context is divided into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System prompt: The instructions set that defines Claude's identity, behavior, and core operational guidelines

&lt;ul&gt;
&lt;li&gt;Skills are loaded here.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;System tools: Built-in capabilities available in every conversation (file operations, execution, web access, agents).&lt;/li&gt;
&lt;li&gt;MCP tools: MCP tools and descriptions of each tool.&lt;/li&gt;
&lt;li&gt;Memory files: Project-specific context files (like CLAUDE.md) that provide persistent knowledge about your projects and preferences.&lt;/li&gt;
&lt;li&gt;Messages: The actual conversation history between you and Claude in the current session.&lt;/li&gt;
&lt;li&gt;Free space: Available context window capacity for additional content.&lt;/li&gt;
&lt;li&gt;Autocompact buffer: Reserved space that triggers automatic context compression when filled to prevent overflow.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Skills context
&lt;/h2&gt;

&lt;p&gt;Claude's path when using skills works like this:&lt;/p&gt;

&lt;p&gt;At the start of a session, Claude scans all available skill files and &lt;strong&gt;reads a short explanation for each one from the frontmatter YAML in the Markdown file&lt;/strong&gt; - this is very token efficient: each skill only takes up a few dozen extra tokens, with the full details only loaded in should the user request a task that the skill can help solve.&lt;/p&gt;

&lt;p&gt;For example, at the very beginning of each session, Claude generates a system context file. In which skills are loaded in a section like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &amp;lt;available_skills&amp;gt;
     &amp;lt;skill&amp;gt;
       &amp;lt;name&amp;gt;analyzing-financial-statements&amp;lt;/name&amp;gt;
       &amp;lt;description&amp;gt;This skill calculates key financial ratios and metrics from financial statement data &lt;span class="k"&gt;for &lt;/span&gt;investment analysis
  &lt;span class="o"&gt;(&lt;/span&gt;project&lt;span class="o"&gt;)&lt;/span&gt;&amp;lt;/description&amp;gt;
       &amp;lt;location&amp;gt;managed&amp;lt;/location&amp;gt;
     &amp;lt;/skill&amp;gt;
     &amp;lt;skill&amp;gt;
       &amp;lt;name&amp;gt;example-skill&amp;lt;/name&amp;gt;
       &amp;lt;description&amp;gt;Demonstrates the basic structure of a Claude Skill. Use this as a template when creating new skills. &lt;span class="o"&gt;(&lt;/span&gt;project&lt;span class="o"&gt;)&lt;/span&gt;&amp;lt;/description&amp;gt;
       &amp;lt;location&amp;gt;managed&amp;lt;/location&amp;gt;
     &amp;lt;/skill&amp;gt;
     &amp;lt;skill&amp;gt;
       &amp;lt;name&amp;gt;playwright-skill&amp;lt;/name&amp;gt;
       &amp;lt;description&amp;gt;Complete browser automation with Playwright. Auto-detects dev servers, writes clean &lt;span class="nb"&gt;test &lt;/span&gt;scripts to /tmp. Test pages, fill forms,
  take screenshots, check responsive design, validate UX, &lt;span class="nb"&gt;test &lt;/span&gt;login flows, check links, automate any browser task. Use when user wants to &lt;span class="nb"&gt;test
  &lt;/span&gt;websites, automate browser interactions, validate web functionality, or perform any browser-based testing. &lt;span class="o"&gt;(&lt;/span&gt;project&lt;span class="o"&gt;)&lt;/span&gt;&amp;lt;/description&amp;gt;
       &amp;lt;location&amp;gt;managed&amp;lt;/location&amp;gt;
     &amp;lt;/skill&amp;gt;
   &amp;lt;/available_skills&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;You can see an example of the whole prompts at leaked prompts at &lt;a href="https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-4.5-sonnet.md" rel="noopener noreferrer"&gt;ageirtj's repo&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;All my skills take approximately 200-250 tokens (including XML tags, descriptions, and metadata). The actual descriptions alone (just the text content) would be 35~40 tokens total.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffi80ak36mai7fykzb05.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffi80ak36mai7fykzb05.webp" alt=" " width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Claude only loads the .yaml-like description and data at the top of the document, and from there it decides if it's worth reading more (Progressive Disclosure):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyz1rrh5eigpqvyi5vc2p.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyz1rrh5eigpqvyi5vc2p.webp" alt=" " width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  NOTE: Skills depend on a coding environment
&lt;/h3&gt;

&lt;p&gt;One thing to note is that the skills mechanism is entirely dependent on the model having access to a filesystem, tools to navigate it, and the ability to execute commands in that environment. The filesystem is your computer, and it can change things in YOUR computer. So you should always verify whether your functions or commands have side effects that could affect your system.&lt;/p&gt;

&lt;p&gt;This can also be beneficial because you are not dealing with external dependencies, but it brings back the "It works in my computer" problem.&lt;/p&gt;

&lt;h1&gt;
  
  
  Skills vs MCP
&lt;/h1&gt;

&lt;p&gt;I mentioned that skills are not FULLY loaded upfront; they load the basic description, and then the agent decides whether it's worth reading more. MCPs used to be designed (And some still are) in a way that all of their tools were loaded up front, taking a lot of context. &lt;strong&gt;But new MCPs are improving their architecture, and they are using the same patterns as Skills to have separate code execution, which brings their context size to similar levels as Skills.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5bqwy1shl9vw61na7hz.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5bqwy1shl9vw61na7hz.webp" alt=" " width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: Technically, you can use scripts in skills and avoid MCPs. (And vice-versa)&lt;/strong&gt;&lt;br&gt;
You can use both together: MCP connections give Claude access to tools, while Skills teach Claude how to use those tools effectively.&lt;br&gt;
MCP connects Claude to external services and data sources. Skills provide instructions for how to complete specific workflows. &lt;/p&gt;
&lt;h2&gt;
  
  
  Skills PROS:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Skills are simple&lt;/strong&gt;: The core simplicity of the skills design is why I'm so excited about it.
MCP is a whole protocol specification, covering hosts, clients, servers, resources, prompts, tools, sampling, roots, elicitation, and three different transports (stdio, streamable HTTP, and originally SSE). Skills are Markdown with a tiny bit of YAML metadata and some optional scripts in whatever you can make executable in the environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills are stable&lt;/strong&gt;: Since skills are just &lt;code&gt;.md&lt;/code&gt; files with scripts, they are usually very stable and simple to maintain.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  MCP PROS:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Can connect to external applications&lt;/strong&gt;: This is the biggest pro in my opinion; If you want an API-like interface that can connect to other applications, this is the way to go, especially since there are many officially supported MCPs from big organizations like Linear/Slack/Stripe. You can also benefit from MCP servers that run the code in the owner's cloud instead of locally.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Things to consider that I didn't delve into:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Reliability, security/isolation, cross-device availability, latency, required runtime permissions, collaboration features, etc...&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Plawright MCP vs skill example.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;DISCLAIMER:&lt;/strong&gt; It's not the same maintainer, so some of the features in the MCP are not in the SKILL and vice versa.&lt;br&gt;
The Playwright skill uses around 100 tokens in context, while the MCP uses ONE HUNDRED times more (10'000 tokens). The main difference is that the Skill has a lot of the functionality the MCP has, but it gets loaded ONLY when it's necessary, while the MCP is always in memory.&lt;/p&gt;

&lt;p&gt;Here is a breakdown of the approximate token use that Playwrite MCP uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  Based on the JSON schema definitions visible to me, here&lt;span class="s1"&gt;'s a rough estimate:

  Simple tools (minimal parameters):
  - browser_close, browser_navigate_back, browser_install, browser_console_messages
  - ~150-250 tokens each

  Medium tools (moderate parameters):
  - browser_resize, browser_navigate, browser_press_key, browser_take_screenshot, browser_wait_for, browser_tabs
  - ~300-500 tokens each

  Complex tools (extensive parameters with nested schemas):
  - browser_evaluate, browser_fill_form, browser_click, browser_type, browser_drag, browser_hover, browser_select_option, browser_run_code
  - ~500-800 tokens each

  Rough total estimate: 8,000-10,000 tokens for all 22 Playwright MCP tools, including their full JSON schema definitions, descriptions, and parameters
  specifications, and metadata.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will say this again, &lt;strong&gt;10'000 tokens in context for something we might not use is not worth it&lt;/strong&gt;. I have personally disabled the Playwright MCP, but I had to change the Skill a bit to fit my work better (which is waay easier to do in Skills, since I have the files right there in my codebase).&lt;/p&gt;

&lt;h2&gt;
  
  
  Semi-outdated MCP criticisms (In my opinion):
&lt;/h2&gt;

&lt;p&gt;I saw this quote by Simon Willson, but I think the main point about spending tokens can be mitigated by good MCP design:&lt;br&gt;
    * "My own interest in MCPs has waned ever since I started taking coding agents seriously. Almost everything I might achieve with an MCP can be handled by a CLI tool instead. LLMs know how to call cli-tool --help, which means you don't have to spend many tokens describing how to use them—the model can figure it out later when it needs to."&lt;br&gt;
    * My comment about this is that there is a new trend with MCPs that do the same as Skills, they display a short description and then point to relevant files and scripts to be used. - But note: For most tasks, it's probably still better to use Skills.&lt;br&gt;
        - &lt;a href="https://www.anthropic.com/engineering/code-execution-with-mcp" rel="noopener noreferrer"&gt;https://www.anthropic.com/engineering/code-execution-with-mcp&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What about RAG?
&lt;/h1&gt;

&lt;p&gt;RAG is a concept that was very hyped before, and it's still relevant. RAG is a middle step where the agent searches and retrieves external data with whatever tools are available to it - grep, vector database, or any relevancy algorithm. &lt;/p&gt;

&lt;p&gt;It can be similar to Skills or MCPs in the way that it's a tool that an LLM can use to improve its answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7squqhnqltg4e88z6s0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7squqhnqltg4e88z6s0.jpg" alt=" " width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What about Claude commands?
&lt;/h1&gt;

&lt;p&gt;Custom slash commands allow you to define frequently-used prompts as Markdown files that Claude Code can execute. There are plenty of pre-loaded commands in Claude code like &lt;code&gt;/context&lt;/code&gt;, &lt;code&gt;/mcp&lt;/code&gt;, &lt;code&gt;/github&lt;/code&gt;, etc... &lt;br&gt;
They behave almost the same as skills in the way that they are some kind of script or prompt that the LLM runs when you tell it to. &lt;/p&gt;

&lt;p&gt;It seems that commands haven't gained a lot of traction, and I think it's because they tend to be focused on small changes. I think of Skills as an orchestrator of commands. If a command is a single function or bash, skills are a group of functions or commands.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding that context is stateless,
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;We pass the whole conversation every time&lt;/em&gt;&lt;br&gt;
One thing that really helped me understand why keeping context clean is important is that LLMs are stateless; in every new message, we are just passing the whole conversation back and forth to the model (Maybe some providers optimize for this?). So every new message ends up being your whole conversation and the latest message attached to it. &lt;/p&gt;

&lt;p&gt;Sending a single-line message at the end of a 400-line discussion with a lot of back-and-forth is a lot different than sending one at the end of a 100-line structured discussion. MCPs and Skills can help us keep this context as small as possible and even save their thoughts in concise documents that we can reference in a new chat with an LLM.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Claude, it's becoming a general agent, an orchestrator. Skills, Commands, MCPs, and Agents make this explicit. And we as developers will have to focus a lot more on managing Context and providing guardrails, scripts, and instructions to restrict the LLM when necessary and let it work in what it does best.&lt;/p&gt;

&lt;p&gt;Even when models are pushing context windows of 1 million tokens, they still struggle to keep track of things we have done in long conversations, so keeping things understandable and documented is still critical.&lt;/p&gt;

&lt;p&gt;Feel free to send me sources and comments about this.&lt;/p&gt;

&lt;h1&gt;
  
  
  Sources:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://support.claude.com/en/articles/12512176-what-are-skills" rel="noopener noreferrer"&gt;https://support.claude.com/en/articles/12512176-what-are-skills&lt;/a&gt;&lt;br&gt;
&lt;a href="https://simonwillison.net/2025/Oct/16/claude-skills/" rel="noopener noreferrer"&gt;https://simonwillison.net/2025/Oct/16/claude-skills/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills" rel="noopener noreferrer"&gt;https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/lackeyjb/playwright-skill?tab=readme-ov-file" rel="noopener noreferrer"&gt;https://github.com/lackeyjb/playwright-skill?tab=readme-ov-file&lt;/a&gt;&lt;br&gt;
&lt;a href="https://news.ycombinator.com/item?id=45619537" rel="noopener noreferrer"&gt;https://news.ycombinator.com/item?id=45619537&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-4.5-sonnet.md" rel="noopener noreferrer"&gt;https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-4.5-sonnet.md&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.anthropic.com/engineering/code-execution-with-mcp" rel="noopener noreferrer"&gt;https://www.anthropic.com/engineering/code-execution-with-mcp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://aws.amazon.com/what-is/retrieval-augmented-generation/" rel="noopener noreferrer"&gt;https://aws.amazon.com/what-is/retrieval-augmented-generation/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://code.claude.com/docs/en/slash-commands" rel="noopener noreferrer"&gt;https://code.claude.com/docs/en/slash-commands&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents" rel="noopener noreferrer"&gt;https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>programming</category>
      <category>llm</category>
    </item>
    <item>
      <title>In Cursor, Context is King.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Sat, 05 Jul 2025 17:07:15 +0000</pubDate>
      <link>https://dev.to/gvegacl/in-cursor-context-is-king-3ai7</link>
      <guid>https://dev.to/gvegacl/in-cursor-context-is-king-3ai7</guid>
      <description>&lt;h1&gt;
  
  
  Executive summary
&lt;/h1&gt;

&lt;p&gt;If there is one thing you should take away from this document, it is to "Document what you are doing in a separate file."&lt;br&gt;
If you have time for a second thing, it is "Add context manually." &lt;/p&gt;
&lt;h1&gt;
  
  
  Understanding Context.
&lt;/h1&gt;
&lt;h2&gt;
  
  
  &lt;a href="https://docs.cursor.com/guides/working-with-context" rel="noopener noreferrer"&gt;Context window&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;First, what is a context window? And how does it relate to effectively coding with Cursor?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A context window is all the context an LLM has when answering a prompt.&lt;/p&gt;

&lt;p&gt;In Cursor, "context" is the information that is provided to the model. There are two types of context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intent context&lt;/strong&gt; defines what the user wants to get out of the model. For example, a system prompt usually serves as high-level instructions for how the user wants the model to behave. Most of the "prompting" done in Cursor is intent context. "Turn that button from blue to green" is an example of stated intent; it is prescriptive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State context&lt;/strong&gt; describes the state of the current world. Providing Cursor with error messages, console logs, images, and chunks of code are examples of context related to state. It is descriptive, not prescriptive.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Providing context to Cursor.
&lt;/h2&gt;

&lt;p&gt;When answering a prompt, Cursor will try to find context by itself, it does this with a &lt;code&gt;proprietary&lt;/code&gt; model that pulls in the parts of your codebase that the model estimates are relevant, such as the current file, semantically-similar patterns in other files, and other information from your session. It also might use "tools" and MCPs like web search to find relevant context.&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;proprietary&lt;/code&gt; model is pretty good, but it falls short when dealing with complex problems. &lt;/p&gt;

&lt;p&gt;I made an experiment to show this. The experiment is a variation of the "Needle in the haystack" test. In this test I placed a riddle in our code, and asked Cursor to solve it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Context experiment
&lt;/h3&gt;

&lt;p&gt;The experiment consisted of a riddle that added a &lt;code&gt;.txt&lt;/code&gt; file of 25k characters ~ &lt;a href="https://www.gptcostcalculator.com/open-ai-token-calculator" rel="noopener noreferrer"&gt;6k tokens&lt;/a&gt; with random text, and a riddle inside the random text. In this case, the riddle was a Caesar cipher with the key at the end of the file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If anyone wants to see the whole experiment, please comment or DM me.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The results of the experiment were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* Gemini 2.5 pro
 - Finds the file correctly ❌
 - Gets the answer correct. ❌

* Claude 4.0 sonnet
 - Finds the files correctly ✅
 - Gets the answer right. ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we see, even with only a 6k context window, the Gemini model can't figure out the answer to the riddle. (6k tokens is about ~850 lines of code, &lt;a href="https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them" rel="noopener noreferrer"&gt;4 characters =~ 1 token&lt;/a&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I haven't confirmed, but I am sure that if I made the puzzle more intricate by adding text and more cross-references, the model would break&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is relevant because imagine Cursor looking for how to answer your prompt in the best way possible, it will look online, it will look at all your files, but it won't read them &lt;strong&gt;UNLESS&lt;/strong&gt; you pass the file into context. (You can test this by seeing how many tokens are passed if you use a custom API token in Cursor)&lt;/p&gt;

&lt;h3&gt;
  
  
  How much context do we have?
&lt;/h3&gt;

&lt;p&gt;In Cursor; Gemini, and Claude have 120k tokens for context. That might seem like a lot, but remember our experiment with 6k context? The models could degrade with way shorter contexts.&lt;/p&gt;

&lt;p&gt;Here is the context of a few things for anyone interested:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Average stack overflow page call &lt;a href="//./experiments/website-context-experiment.md"&gt;~15k tokens&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The code files in a mid-sized company are at least a few million characters, which is at least 0.75 Million Tokens

&lt;ul&gt;
&lt;li&gt;Average characters per file is about 4,721 characters ~= 1k tokens.&lt;/li&gt;
&lt;li&gt;Large files for an average company are ~= 30k characters ~= 8k tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  How Cursor handles a prompt.
&lt;/h1&gt;

&lt;p&gt;This is how the Cursor handles a prompt:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You write your prompt and add your context. Then press enter.&lt;/li&gt;
&lt;li&gt;Cursor uses it's proprietary model to analyze your prompt and context. You haven't hit the AI model yet (Gemini, Claude, etc...)

&lt;ul&gt;
&lt;li&gt;There is no official documentation that says this directly, but there are allusions to it in Cursor official docs, and in Anthropic's system prompt docs. (And the leaked system prompt from Anthropic around May 2025).

&lt;ul&gt;
&lt;li&gt;Cursor prompts some tools with a proprietary LLM or algorithm to decide what MCPs to use.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Cursor takes the context you added, AND it takes what it thinks is the relevant context and appends it to the api.

&lt;ul&gt;
&lt;li&gt;Cursor also adds a small system prompt (can't find official docs. But cursor adds about ~1k tokens to all your requests. I assume those are its custom instructions.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The API/LLM then processes the prompt, and you receive the answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  How to improve my prompts? - Keep track of your decisions in a document.
&lt;/h1&gt;

&lt;p&gt;Finally, the good part. Here is what to do if you want to  significantly improve the context that you send Cursor:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make one or two documents depending on how big is your task, I usually call it "PLAN.md" and/or "TASKS.md"&lt;/li&gt;
&lt;li&gt;Write down the problem, objective, insights and thoughts you have, and a plan on "PLAN.md", you can use AI to help you write the plan. It's usually useful to ask AI to write a plan with "atomic" steps, so it gives you small steps to follow.&lt;/li&gt;
&lt;li&gt;Start working on the problem, every time you make progess (progress might be a new insight, a new piece of code, etc...), write down what you did on "TASKS.md", it's even better if you can reference what you did at "PLAN.md" too. Then commit. &lt;/li&gt;
&lt;li&gt;Keep going. Remember to write new insights, failed attempts, and sources too in your documents. This development loop forces two things.

&lt;ul&gt;
&lt;li&gt;You will think more about what you are doing, which is a lot of help as a developer.&lt;/li&gt;
&lt;li&gt;The AI will keep close track of context, and you can easily revert and correct if it goes off track. The AI will also be way better at problem-solving.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>cursor</category>
      <category>ai</category>
      <category>programming</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>How to organize your project's folders - A quick guide to repository and folder structures.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Sun, 15 Oct 2023 15:49:17 +0000</pubDate>
      <link>https://dev.to/gvegacl/how-to-organize-your-projects-folders-a-quick-guide-to-repository-and-folder-structures-5fje</link>
      <guid>https://dev.to/gvegacl/how-to-organize-your-projects-folders-a-quick-guide-to-repository-and-folder-structures-5fje</guid>
      <description>&lt;p&gt;Depending on your objectives and needs, there are many ways of organizing a project in React. But some patterns are considered best practices; here, I'll explain a few.&lt;/p&gt;

&lt;h1&gt;
  
  
  Atomic Design.
&lt;/h1&gt;

&lt;p&gt;Atomic Design is a concept introduced by Brad Frost, and it's a methodology to build consistent and reusable design systems, especially in web interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Atoms
&lt;/h2&gt;

&lt;p&gt;Atoms are the basic building blocks in this methodology. They're the smallest possible components, like form labels, buttons, inputs, or even design tokens such as colors, fonts, etc. Atoms can be abstract and don't necessarily represent the final product, but they help to create a consistent interface and development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Molecules
&lt;/h2&gt;

&lt;p&gt;Molecules are combinations of two or more atoms that form relatively simple components together. An example could be a form label, a text input, and a button combined to make a search form. While atoms can exist in isolation (like a button), molecules find their true meaning when used in conjunction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Organisms.
&lt;/h2&gt;

&lt;p&gt;Organisms are relatively complex UI components composed of groups of molecules (and possibly atoms). Examples might include the header of a website with a logo (atom), a navigation menu (molecule), and a search form (molecule). Organisms provide context for the molecules and demonstrate how molecules can work together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /components
    /atoms
      Button.jsx
      Icon.jsx
      ...
    /molecules
      FormInput.jsx
      UserAvatar.jsx
      ...
    /organisms
      Header.jsx
      Sidebar.jsx
      ...
    /templates
      MainLayout.jsx
      UserLayout.jsx
      ...
    /pages
      HomePage.jsx
      UserProfilePage.jsx
      ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  By feature or Domain.
&lt;/h1&gt;

&lt;p&gt;This structure is popular for large projects. Here, we group components by the feature they relate to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /components
    /Button
      Button.jsx
      Button.test.jsx
      Button.css
    /Modal
      Modal.jsx
      Modal.test.jsx
      Modal.css
  /features
    /Todo
      /components
        TodoList.jsx
        TodoItem.jsx
      TodoActions.js
      TodoReducer.js
    /User
      /components
        UserProfile.jsx
        UserSettings.jsx
      UserActions.js
      UserReducer.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  By File Type
&lt;/h1&gt;

&lt;p&gt;In smaller projects or applications with many shared components, it might make sense to group files by their type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /components
    Button.jsx
    Modal.jsx
    ...
  /containers
    TodoContainer.jsx
    UserContainer.jsx
    ...
  /actions
    TodoActions.js
    UserActions.js
    ...
  /reducers
    TodoReducer.js
    UserReducer.js
    ...
  /styles
    Button.css
    Modal.css
    ...

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Domain-driven Design (DDD)
&lt;/h1&gt;

&lt;p&gt;For projects that closely align with domain-driven Design, you might structure your folders around aggregates, entities, and value objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /User
    UserAggregate.js
    UserEntity.js
    UsernameValue.js
    ...
  /Product
    ProductAggregate.js
    ProductEntity.js
    PriceValue.js
    ...

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Modules or Packages
&lt;/h1&gt;

&lt;p&gt;Modules are self-contained units of code that encapsulate a specific functionality or feature, often used in mono repo structures or when scaling with multiple teams.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /modules
    /Todo
      TodoView.jsx
      TodoLogic.js
      TodoService.js
      ...
    /User
      UserView.jsx
      UserLogic.js
      UserService.js
      ...

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;The takeaway is to keep your structure simple. It should be intuitive for developers to know where to place their files and easy for them to be consistent. &lt;br&gt;
I showed a few common structures in this article, but feel free to use what fits your team.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Job hunting in Canada. (And tips for recent immigrants)</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Sat, 07 Oct 2023 15:46:40 +0000</pubDate>
      <link>https://dev.to/gvegacl/job-hunting-in-canada-and-tips-for-recent-immigrants-mo3</link>
      <guid>https://dev.to/gvegacl/job-hunting-in-canada-and-tips-for-recent-immigrants-mo3</guid>
      <description>&lt;p&gt;I got laid off at the beginning of September 2023. And I was lucky enough to get a job offer from another company two weeks later. I have also worked for over eight companies as a contractor and had to go through the same hoops in each.&lt;/p&gt;

&lt;p&gt;This piece is not a guide to get into big tech, but rather somewhere in the middle-high range where you can grow, have a balance, and still make good money. So here are my five learnings from my experience:&lt;/p&gt;

&lt;h1&gt;
  
  
  Be a good engineer.
&lt;/h1&gt;

&lt;p&gt;The article's most essential and irreplaceable point is that you can't swindle your way around getting a software developer job. You need to read and put in the effort to practice coding challenges.&lt;br&gt;
I recommend a few resources for this: &lt;a href="https://roadmap.sh/" rel="noopener noreferrer"&gt;roadmap.sh&lt;/a&gt; will familiarize you with the concepts you need to learn and provide valuable resources to understand them.&lt;/p&gt;

&lt;p&gt;I also recommend &lt;a href="https://neetcode.io/" rel="noopener noreferrer"&gt;neetcode.io&lt;/a&gt; to try your hand at practicing coding challenges and essential concepts.&lt;/p&gt;

&lt;h1&gt;
  
  
  Apply to everything fast.
&lt;/h1&gt;

&lt;p&gt;This advice is controversial, but this is what works for me and a few other people I've talked with. Our current job market is a mess; Some companies post ghost jobs that they don't intend to fill, [1][2], others fill the position and forget their post, and others are almost done with their recruitment process, so the odds are against you, and others.&lt;/p&gt;

&lt;p&gt;My solution is to apply to everything quickly, sort postings by date, and apply to every job related to what you want, even in companies you don't like.&lt;br&gt;
Now, you either get an opportunity to interview for a company you like or you get practice interviewing with a company you don't like. Remember, you can always turn down an offer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: I have heard that this is mean and that you are wasting people's time. This point is debatable, but the short answer is that most companies have their interview process automated, and most companies don't care if they are wasting your time with many rounds of interviews. You should follow your moral compass, but don't feel bad for doing what you must do.&lt;/p&gt;

&lt;p&gt;I usually hear this kind of argument from underrepresented people in tech, especially women. If it helps, most companies want to attract more BIOPC, LGBTQ+, and woman coders, so apply liberally. [3] [4] [5]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where to apply?
&lt;/h2&gt;

&lt;p&gt;I don't like &lt;a href="https://www.linkedin.com/in/cesar-leonardo-vega-galvan/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, but in Canada, there are excellent offers at &lt;a href="https://ca.indeed.com/?r=us" rel="noopener noreferrer"&gt;Indeed.com&lt;/a&gt;, &lt;a href="https://www.levels.fyi/" rel="noopener noreferrer"&gt;Levels.fyi&lt;/a&gt; and my favorite &lt;a href="https://hired.com/" rel="noopener noreferrer"&gt;Hired.com&lt;/a&gt;, a friend also recommended &lt;a href="https://simplify.jobs/" rel="noopener noreferrer"&gt;simplify.jobs&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tips for immigrants
&lt;/h1&gt;

&lt;p&gt;In Canada, it is generally not legal for employers to ask about your immigration status during the hiring process [6]. But if you are requested your immigration status after receiving a job offer, you should disclose it at this point. [7].&lt;/p&gt;

&lt;p&gt;But then again, if you want the job, you will disclose it if they ask. My advice is to be honest, always have your papers in order, and keep your answers short so you don't dig a hole for yourself. If you are worried about this, contact an immigration lawyer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Be patient.
&lt;/h1&gt;

&lt;p&gt;I sent almost 100 applications before getting an offer, and earlier in my career, there were times when I spent months and over 300 applications before getting a job. Be patient and learn what you are comfortable negotiating. Plenty of companies are out there, and work is a big part of the day, so feel free to let one offer slip out if you don't fit in the culture. But don't be too picky, you might realize that you enjoy working at a company after all.&lt;/p&gt;

&lt;h1&gt;
  
  
  Sources:
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://news.yahoo.com/companies-posting-fake-ghost-jobs-111500854.html?guccounter=1&amp;amp;guce_referrer=aHR0cHM6Ly93d3cucGhpbmQuY29tLw&amp;amp;guce_referrer_sig=AQAAABhRAbWL9NTEjsxkobD2LzASiIPOFuoimnYlNxWPwZqLZOh0002SKHLoHq2xtntv1Wx1KS1T4GaY1JxrZsYYEdm0zd5unOeeZRDYaYV6C3EkjJWED_u6Ni_7_xI_WFiA0OVBGvnKQZi7yHTZl1LaQYqO285-5WBVRhLQnNVmctBt" rel="noopener noreferrer"&gt;news.yahoo.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.forbes.com/sites/robinryan/2022/11/30/be-careful-of-employers-posting-ghost-jobs/?sh=14c64700142d" rel="noopener noreferrer"&gt;Forbes.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.forbes.com/sites/committeeof200/2023/02/28/to-attract-more-women-in-tech-the-industry-needs-to-change/?sh=56a9b3ab3628" rel="noopener noreferrer"&gt;Forbes.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hbr.org/2021/12/two-ways-to-improve-gender-balance-in-tech" rel="noopener noreferrer"&gt;hbr.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.forbes.com/sites/forbescommunicationscouncil/2023/04/14/why-tech-companies-should-hire-more-women-and-make-it-a-part-of-their-csr-policy/?sh=5b99df33aac3" rel="noopener noreferrer"&gt;Forbes.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.canadavisa.com/moving-to-canada-from-the-u-s.html" rel="noopener noreferrer"&gt;Canadavisa.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/pulse/so-you-legally-entitled-work-canada-dorothy-keenan/" rel="noopener noreferrer"&gt;LinkedIn.com&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>webdev</category>
      <category>job</category>
    </item>
    <item>
      <title>Fixing (and removing) commits in a git branch for beginners.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Sun, 01 Oct 2023 14:34:27 +0000</pubDate>
      <link>https://dev.to/gvegacl/fixing-and-removing-commits-in-a-git-branch-for-beginners-4jp9</link>
      <guid>https://dev.to/gvegacl/fixing-and-removing-commits-in-a-git-branch-for-beginners-4jp9</guid>
      <description>&lt;p&gt;We have all been there. You want to merge and have a different set of commits that you want to have. Maybe you rebased a branch you shouldn't have or checked out from the wrong branch. But don't worry, fixing it is easy.&lt;/p&gt;

&lt;p&gt;In this article, I will show a few techniques to get your branch exactly how you want it and avoid merging code and commits that do not belong in your target branch. &lt;/p&gt;

&lt;p&gt;Let's start with an example where we have four commits:&lt;br&gt;
&lt;code&gt;git log --oneline&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;c761a8f (HEAD -&amp;gt; my-feature) commit-3
e056796 bad-commit-1
269a02d commit-2
ceaab87 commit-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can see that a bad commit snuck into our branch, so how do we fix it?&lt;br&gt;
It's simple: First, we make sure the commit is unnecessary and want to remove it.&lt;br&gt;
We can do this with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git show e056796&lt;/code&gt;&lt;br&gt;
or &lt;br&gt;
&lt;code&gt;git diff e056796^!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And then, we can see what our commit did.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pro tip: This command will look prettier if you have customized your terminal with tools like ohMyZSH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our second step is to take that commit out of our history. I do this by rebasing our branch. We would do an interactive rebase to our target branch in our example.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git rebase -i target-branch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;An editor (often Vim or Nano) will open, showing the last commits. It'll look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pick ceaab87 commit-1
pick 269a02d commit-2
pick e056796 bad-commit-1
pick c761a8f commit-3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, to keep the commits we want, delete the line corresponding to the bad commit (bad-commit-1):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
pick ceaab87 commit-1
pick 269a02d commit-2
pick c761a8f commit-3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exit and save the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pro tip: For Vim, press "i" to interact with the text. And then, you click "ESC" -&amp;gt; "wq" to save and exit.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, if you've already pushed your branch to a remote repository before this change, you'll need to &lt;code&gt;force push&lt;/code&gt; your changes:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push origin your-branch-name --force-with-lease&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;And now you have a clean branch without all those pesky commits. Always double-check with your team if those commits are unnecessary, and remember that this will only affect YOUR branch, so don't be too scared to go through the process.&lt;/p&gt;

</description>
      <category>git</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding Coupling in React: Best practices and Examples</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Mon, 25 Sep 2023 19:34:38 +0000</pubDate>
      <link>https://dev.to/gvegacl/understanding-coupling-in-react-practices-and-examples-1h1n</link>
      <guid>https://dev.to/gvegacl/understanding-coupling-in-react-practices-and-examples-1h1n</guid>
      <description>&lt;p&gt;Coupling refers to the degree of interdependence between different modules or classes in a system.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Coupling?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Coupling speaks to how closely connected different components or modules are within an application. High coupling means that changes in one module may necessitate changes in many other modules. This results in a codebase that becomes increasingly difficult to maintain and modify over time. As such, best practices usually recommend minimizing coupling.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Separate Components by Responsibility&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A prevalent form of coupling occurs when a single file or component assumes multiple responsibilities (Look at the Single Responsibility Principle). We should avoid patterns where a component takes on multiple roles; For example, having a component determine if it should render as a header or footer based on props:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HeaderOrFooter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;isHeader&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isHeader&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;header&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;)
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;footer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;  &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, consider creating distinct components for different roles and handling display logic at the parent level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nx"&gt;isHeader&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Header&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Footer&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;header&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Footer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;footer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;  &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Avoid Prop Drilling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Prop drilling refers to the practice of passing props from a parent component down through its descendants. If your components are tightly intertwined with a shared state, it's a clear sign of tight coupling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;....&lt;/span&gt; &lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;IChildComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GrandChildComponent&lt;/span&gt; &lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;....&lt;/span&gt; &lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To combat this, you can use shared context or architect your components with a clearer separation of concerns. Remember to use context carefully to avoid bloating the global state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProp3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;....&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GrandChildComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GrandChildComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SharedContext&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Fetch Data Close to Where It's Used&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is more of a personal preference, but I like fetching and managing data as close to its usage point as possible. This helps reduce unnecessary props passed down and keeps data handling within the concerned component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useGetData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A better approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ParentComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ChildComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useGetData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;....&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;In conclusion, managing coupling is essential for scalable and maintainable applications. By separating concerns, avoiding prop drilling, and fetching data where it's used, we can significantly reduce the effects of high coupling and build more robust React applications.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>useContext to manage state between React Sibling Components.</title>
      <dc:creator>Cesar Vega</dc:creator>
      <pubDate>Tue, 12 Sep 2023 14:47:26 +0000</pubDate>
      <link>https://dev.to/gvegacl/usecontext-to-manage-state-between-react-sibling-components-3apj</link>
      <guid>https://dev.to/gvegacl/usecontext-to-manage-state-between-react-sibling-components-3apj</guid>
      <description>&lt;p&gt;Have you ever wanted two separate components that share common state? Maybe a controller component and a display component where one component deals with the controls and the other with displaying it. Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setA&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Box&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grid gap-4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;gridTemplateColumns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1fr 1fr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GameGrid&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GameControls&lt;/span&gt; &lt;span class="nx"&gt;setA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setA&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;setB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setB&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;setC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setC&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Box&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It might be okay if we just pass a couple props, but even with few props it feels wrong. So, how do we do it?&lt;/p&gt;

&lt;h2&gt;
  
  
  Share context between sibling components.
&lt;/h2&gt;

&lt;p&gt;To do this you need to create a context object and wrap the components in it. And then you can get the context in each object, regardless of where you manage the sate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GameContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;IGameControls&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="na"&gt;setA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
  &lt;span class="p"&gt;....&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Game&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;contextValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IGameControls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;setA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;setB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;....&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GameContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;contextValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Box&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grid gap-4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;gridTemplateColumns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1fr 1fr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GameGrid&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GameControls&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Box&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/GameContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One important thing to pay attention to is that &lt;strong&gt;we only share this state between the sibling components&lt;/strong&gt;, so the rest of the code is not burdened by this data.&lt;/p&gt;

&lt;p&gt;And now we can get the context in each component easily:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const { a, setA, .... } = useGameContext();&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra sources:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/53648661/how-to-share-state-between-child-component-siblings-in-reactjs" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/53648661/how-to-share-state-between-child-component-siblings-in-reactjs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/learn/sharing-state-between-components" rel="noopener noreferrer"&gt;https://react.dev/learn/sharing-state-between-components&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>designpatterns</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
