<?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: Mubashir Taj</title>
    <description>The latest articles on DEV Community by Mubashir Taj (@mubashirtaj).</description>
    <link>https://dev.to/mubashirtaj</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%2F4141856%2F77fc56be-e43a-4045-a9ec-be31ab5a3b47.jpg</url>
      <title>DEV Community: Mubashir Taj</title>
      <link>https://dev.to/mubashirtaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mubashirtaj"/>
    <language>en</language>
    <item>
      <title>Redis vs Memcached: Picking Your Cache</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Thu, 26 Nov 2026 13:14:03 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/redis-vs-memcached-picking-your-cache-ci4</link>
      <guid>https://dev.to/mubashirtaj/redis-vs-memcached-picking-your-cache-ci4</guid>
      <description>&lt;p&gt;Almost every backend system eventually needs a cache. A database that answers every read directly becomes the bottleneck sooner or later, so teams put a fast in-memory store in front of it. The two names that come up in that conversation are Redis and Memcached. Both are in-memory key value stores, both are fast, and both have been running in production for well over a decade. They are not interchangeable, though. They were built for different jobs, and the differences show up in data structures, persistence, clustering, and eviction. This article compares the two engines directly, so you can make the choice with the trade-offs in front of you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each engine is
&lt;/h2&gt;

&lt;p&gt;Memcached started in 2003 as a cache for LiveJournal. Its job was simple: keep frequently read database rows in memory so the database did fewer reads. That narrow job is still its whole design. Memcached stores opaque blobs under string keys. It does not know what is inside a value, it does not offer data structures, and it does not persist anything to disk. If a node restarts, its cache is empty, and the database takes the load again until the cache warms up.&lt;/p&gt;

&lt;p&gt;Redis arrived in 2009 with a wider ambition. It is a data structure server that happens to be excellent as a cache. Strings, hashes, lists, sets, sorted sets, streams, and geospatial indexes are all native. Values have types, and the server understands them, so operations like incrementing a counter or adding a member to a set happen atomically on the server instead of in a read, modify, write round trip from the client. Redis can also persist data to disk, replicate it, and run as a primary store for some workloads, which is a different job from pure caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data structures and operations
&lt;/h2&gt;

&lt;p&gt;The data model is the biggest difference between the two, and it decides most of the rest.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Memcached has exactly one data type: a byte string. Your application serializes a value, usually JSON or a binary format, and stores it under a key. The server never inspects the contents. That simplicity is a strength when all you need is a dumb, fast lookup. It is a weakness when you need to change part of a value, because the only option is to fetch the whole blob, modify it, and write it back, which is slower and racy under concurrency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redis has a typed data model. A string can be a counter you increment with INCR. A hash can hold the fields of a user session, and you can update one field with HSET without touching the rest. A sorted set can hold a leaderboard, ordered by score, and you can fetch the top ten with a single command. A list can act as a queue, a set can hold unique tags, and a stream can hold an append-only log. These operations run on the server, atomically, which removes whole classes of race conditions that client side read-modify-write cycles introduce.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redis also supports Lua scripting and, in recent versions, a functions API, so small pieces of logic can run on the server next to the data. Memcached has no equivalent. If your access pattern is plain get and set of whole values, the extra machinery in Redis buys nothing. If your access pattern involves counters, rankings, queues, or partial updates, Redis removes work from your application code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Persistence
&lt;/h2&gt;

&lt;p&gt;Memcached keeps everything in RAM and nothing on disk. A restart, a crash, or a deployment that replaces the node wipes the cache completely. For a pure cache this is acceptable by design: the database still holds the truth, and the cache refills as requests arrive. The cost is a cold start. After a restart, every request misses until the working set is rebuilt, and the database absorbs a surge of reads during that window.&lt;/p&gt;

&lt;p&gt;Redis offers two persistence mechanisms. RDB snapshots write the whole dataset to disk at intervals, and AOF logs every write operation so the dataset can be replayed. You can run with both, one, or neither. With persistence enabled, a Redis node can restart and reload its data instead of starting empty. That is also why Redis is sometimes used as a primary store for data that can tolerate some loss, such as sessions or job queues. Persistence is not free. Snapshots and write logs add disk I/O and configuration surface, and AOF replay on a large dataset can take minutes. If you only need a cache, you can disable persistence entirely and Redis behaves like Memcached in this respect, with a warm restart as the only thing you give up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eviction policies
&lt;/h2&gt;

&lt;p&gt;Both engines evict data when memory fills up, but Redis gives you more control over how it happens.&lt;/p&gt;

&lt;p&gt;Memcached uses a slab allocator with LRU eviction inside each slab class. When a slab class is full, the least recently used item in that class is evicted. The behavior is predictable and simple, but it is one policy for everything. You cannot treat session keys differently from rendered page fragments, except by setting TTLs per key.&lt;/p&gt;

&lt;p&gt;Redis lets you pick a policy per instance. The common options are no eviction, which returns errors on writes when memory is full, allkeys-lru, which evicts the least recently used key across the whole dataset, volatile-lru, which only evicts keys that have a TTL set, allkeys-random, and volatile-ttl, which evicts the key with the shortest remaining TTL. This matters in practice. A cache that holds both permanent reference data and short lived session tokens should not evict reference data to make room for sessions. With volatile-lru, the permanent keys are safe and only expiring keys compete for space. Memcached cannot express that distinction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clustering and scaling
&lt;/h2&gt;

&lt;p&gt;Memcached scales by adding nodes and letting the client decide which node holds a key. The standard approach is consistent hashing on the client side. The server has no knowledge of the cluster, which keeps the design simple and fast, but it also means the client library owns sharding, and adding or removing a node reshuffles some keys. There is no replication, no failover, and no built-in way to move data between nodes. If a node dies, its keys are gone until they are rebuilt from the database.&lt;/p&gt;

&lt;p&gt;Redis Cluster shards data across nodes with hash slots, and the cluster itself knows the mapping, so clients can ask any node where a key lives. Redis also supports replication, with replicas that can be promoted when a primary fails, and Sentinel or cluster mode for automatic failover. A Memcached fleet is a set of independent nodes, and your application must tolerate losing any of them at any time. A Redis deployment can be built for high availability, with data surviving a single node failure. The price is operational complexity: cluster setup, slot migration, and failover behavior all need understanding and testing.&lt;/p&gt;

&lt;p&gt;For a single node, the two engines are comparable in raw throughput, both comfortably handling tens of thousands of operations per second. Redis is single threaded for command execution, which keeps its behavior simple and deterministic, while Memcached is multithreaded and can use multiple cores on one box. In practice, network and client overhead dominate long before either engine saturates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Protocol and clients
&lt;/h2&gt;

&lt;p&gt;Memcached speaks a simple text and binary protocol that is easy to implement, and clients exist for every language. Redis speaks RESP, its own text based protocol, and also has clients for every language. Both are straightforward to use from Go or Node, and both have mature client libraries with connection pooling and cluster support.&lt;/p&gt;

&lt;p&gt;A quick comparison in Go shows how similar the basic usage looks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Redis with go-redis&lt;/span&gt;
&lt;span class="n"&gt;rdb&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Addr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"localhost:6379"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user:42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`{"name":"Sara","plan":"pro"}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Hour&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="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;rdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user:42"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;rdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Incr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"pageviews:home"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Result&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Memcached with gomemcache&lt;/span&gt;
&lt;span class="n"&gt;mc&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;memcache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;New&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"localhost:11211"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;memcache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user:42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Value&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="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`{"name":"Sara","plan":"pro"}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Expiration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;mc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cached&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;mc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"user:42"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Redis snippet does one thing the Memcached snippet cannot: increment a counter on the server. Everything else is the same shape, a client, a key, and a value. The choice between them is not about the API. It is about whether your workload needs the server to understand your data.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to pick each
&lt;/h2&gt;

&lt;p&gt;Choose Memcached when the job is strictly caching whole values in front of a database. It is the simplest tool for that job, it is battle tested, its multithreaded design scales well on a single box, and its lack of features is a feature: there is less to misconfigure. Typical fits are rendered HTML fragments, serialized API responses, and database query results that are fetched whole and invalidated by TTL or by explicit deletion. If you can describe your cache as a map from string keys to opaque blobs, Memcached is enough, and the extra machinery of Redis is cost without benefit.&lt;/p&gt;

&lt;p&gt;Choose Redis when you need anything beyond a dumb key value lookup. Counters, leaderboards, rate limiters, queues, session stores with field level updates, pub/sub messaging, and geospatial queries all map naturally onto Redis data structures. Choose Redis when persistence matters, because a restart should not empty the cache, or when you need replication and failover rather than accepting that a dead node means a cold cache. The operational cost is real, so do not choose Redis by default for every project. Choose it when a concrete requirement points at it.&lt;/p&gt;

&lt;p&gt;One last consideration is team knowledge. Both engines are simple to start with, but Redis has more features to learn and more ways to misconfigure, from eviction policies to persistence settings to cluster topology. If the team already runs Redis in production, using it for caching too is usually the right call, because one system to operate beats two. If the team runs neither, and the workload is plain caching, Memcached is the smaller thing to learn and operate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Redis and Memcached solve overlapping problems from different starting points. Memcached is a purpose built cache: simple, fast, and deliberately limited. Redis is a data structure server that can act as a cache, with typed values, server side operations, persistence, replication, and clustering. The right choice follows from the workload. Whole value caching with no extra requirements points to Memcached. Counters, rankings, queues, partial updates, persistence, or failover point to Redis. Either engine serves a plain cache well. The expensive mistake is picking the simple one and then rebuilding the missing features in application code, or picking the powerful one and paying its operational cost for a job the simple one already did.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>backend</category>
      <category>redis</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How Google Search Returns Results in Under a Second</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Wed, 25 Nov 2026 13:16:43 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/how-google-search-returns-results-in-under-a-second-26h8</link>
      <guid>https://dev.to/mubashirtaj/how-google-search-returns-results-in-under-a-second-26h8</guid>
      <description>&lt;p&gt;Type a query into Google Search and the results arrive in well under a second. That feels ordinary now, but it is worth pausing on what the system has to do in that time. The web contains hundreds of billions of pages. A single query has to find the pages that match, rank them by relevance and quality, and return the top ten, all while thousands of other people are doing the same thing at the same moment. No single machine can hold the index, and no single machine can answer the query fast enough on its own. The answer is a distributed system built from a few simple ideas, applied at enormous scale: crawl everything in advance, organize the index so lookups are cheap, split the work across tens of thousands of machines, and cache aggressively at every layer. This article walks through each piece, in the order a query actually flows through the system.&lt;/p&gt;

&lt;p&gt;The first thing to understand is that almost no work happens at query time. The expensive work happens in advance, continuously, in the background. Crawlers fetch pages from across the web, day and night. The fetched pages are parsed, and the text is extracted and analyzed. Links are followed to discover new pages. Copies of pages are stored so the system can show cached versions and reprocess content without fetching it again. This pipeline runs constantly, because the web changes constantly: news pages update within minutes, product pages change prices, and new pages appear every second. By the time you type a query, the system has already done the slow work of finding and reading the pages. The query itself is a lookup against data structures that were built for exactly that purpose.&lt;/p&gt;

&lt;p&gt;The central data structure is the inverted index, and it is the same idea that powers search inside a database or a documentation site, scaled up. A normal index maps a document to the words it contains. An inverted index flips that around: it maps each word to the list of documents that contain it, along with the positions of the word inside each document. When you search for "postgres connection pooling", the system looks up three posting lists, one per word, and intersects them to find documents containing all three. The positions matter because they let the system tell a document where the words appear next to each other from a document where they appear in unrelated paragraphs. The phrase match is a strong relevance signal, and it is cheap to compute once positions are stored.&lt;/p&gt;

&lt;p&gt;A simplified inverted index in Go shows the shape of the idea:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s2"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Posting&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;DocID&lt;/span&gt;     &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Positions&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Index&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;postings&lt;/span&gt; &lt;span class="k"&gt;map&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="nc"&gt;Posting&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;term&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;docID&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;postings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DocID&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;docID&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Positions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Positions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Posting&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;DocID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;docID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Positions&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;pos&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="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;postings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;main&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;idx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;postings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&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="nc"&gt;Posting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"postgres"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pooling"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"postgres"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;postings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"postgres"&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;This toy version stores everything in memory on one machine. The real index is far too large for that, which leads to the next idea: sharding. The index is split into shards, and each shard lives on its own set of machines. There are two common ways to split it. One way is by document: each shard holds a slice of the documents, with a complete index over just those documents. The other way is by term: each shard holds the posting lists for a slice of the vocabulary. Document based sharding is the more common choice for web search, because a query then goes to every shard, each shard returns its best matches, and the results are merged. Term based sharding sends each query term to a different shard, which complicates merging and ranking. Either way, the point is the same: no single machine holds the whole index, and the work is spread across many machines that run in parallel.&lt;/p&gt;

&lt;p&gt;The query path starts when your request reaches a front end server. The front end parses the query, normalizes it, and expands it: it handles spelling correction, recognizes synonyms, and identifies entities such as people, places, and products. This is where the system decides that a query about a recent event is a news query, or that a query with a location implies local results. The parsed query is then fanned out to the index shards. Each shard searches its portion of the index, scores its candidate documents, and returns its top results. A fan out like this only works if every shard answers quickly, because the total response time is set by the slowest shard, not the fastest. That constraint shapes the whole design: shards are kept small enough to answer in tens of milliseconds, machines are replicated so a slow or failed replica can be skipped, and strict timeouts cut off stragglers rather than letting one bad machine delay every query.&lt;/p&gt;

&lt;p&gt;A simplified fan out in Go illustrates the pattern, with each shard queried in its own goroutine and results merged as they arrive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s2"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ShardID&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;DocIDs&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;queryShard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Millisecond&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;ShardID&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="nc"&gt;DocIDs&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;func&lt;/span&gt; &lt;span class="nf"&gt;fanOut&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&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;shards&lt;/span&gt; &lt;span class="kt"&gt;int&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="nc"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shards&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;shards&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;queryShard&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="n"&gt;q&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;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&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="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shards&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;shards&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;out&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="n"&gt;results&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;main&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;results&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;fanOut&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"postgres connection pooling"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&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;The real system adds timeouts, retries to a replica, and a merge step that combines scores across shards. The shape is the same: parallel calls, bounded waiting, merge at the end. This is the same fan out pattern you see in any distributed search or aggregation service, and it is worth learning well, because the failure modes are also the same. A shard that is slow every time needs investigation, not a longer timeout, and a merge step that waits for every shard will always be as slow as the worst one.&lt;/p&gt;

&lt;p&gt;Once candidate documents arrive from the shards, the system ranks them. Ranking is not a single score but a pipeline of stages. The first stage is cheap and broad: it scores a large set of candidates using fast signals such as term frequency, document length, and whether the terms appear in the title. The second stage is expensive and narrow: it takes the top few hundred candidates and applies heavier signals, including machine learning models that consider hundreds of features. Those features include the quality and authority of the page, measured largely through the link graph, the freshness of the content, the match between the query and the page, and the behavior of users who issued similar queries in the past. The link graph matters because a page that many other pages link to, especially pages that are themselves well linked, is more likely to be authoritative than a page nobody references. Freshness matters because a query about a breaking event should return minutes old coverage, not a five year old article.&lt;/p&gt;

&lt;p&gt;Caching sits at every layer, and it is what makes the latency budget possible. Popular queries are cached at the front end, so a query that thousands of people issue every day may never reach the index shards at all. The posting lists for common terms are cached in memory on the shard machines. The rendered result pages for common queries are cached closer to the user. There are also caches for spelling correction, for entity lookups, and for the snippets shown under each result. Caching works because query traffic is highly skewed: a small fraction of distinct queries accounts for a large share of total traffic. The long tail of rare queries still has to hit the index, but the cache absorbs the repeated load and leaves capacity for the queries that are genuinely new.&lt;/p&gt;

&lt;p&gt;There are also systems around the edges that the query path depends on. The crawler has to respect robots rules, avoid overloading small sites, and prioritize pages that change often or are linked to frequently. The index has to be updated incrementally, because rebuilding hundreds of billions of pages from scratch is not feasible on a useful schedule. Fresh documents are added to the index in near real time, while the bulk of the index is rebuilt in batches. Spell checking, query understanding, and result presentation all have their own services, and each one has its own latency budget, because the total budget for the whole request is under a second, and every millisecond spent in one service is a millisecond unavailable to the others.&lt;/p&gt;

&lt;p&gt;The lesson for backend engineers is not that you should build a search engine. It is that the patterns in this system show up everywhere at smaller scale. Precompute in the background instead of at request time. Use an inverted index when you need to find documents by their contents. Shard by document when you need parallel search with simple merging. Fan out with timeouts and replicas, and never let the slowest dependency set your latency without a bound. Rank in stages, cheap first and expensive second. Cache the hot paths, and measure the skew in your own traffic before deciding what to cache. None of these ideas is exotic on its own. The achievement is combining them so that a query across hundreds of billions of pages returns in the time it takes to blink. That combination, done carefully and measured relentlessly, is what system design at scale actually looks like.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>backend</category>
      <category>programming</category>
    </item>
    <item>
      <title>Go vs Java for Backend Services: A Practical Comparison</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Sat, 21 Nov 2026 13:14:09 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/go-vs-java-for-backend-services-a-practical-comparison-ldd</link>
      <guid>https://dev.to/mubashirtaj/go-vs-java-for-backend-services-a-practical-comparison-ldd</guid>
      <description>&lt;p&gt;Go and Java are the two most common answers to the same question: what language should this backend service be written in? Both are proven in production at enormous scale, both have strong ecosystems, and both will serve a well built API without drama. The differences are real, but they are not the differences that most comparison articles emphasize. Raw benchmark numbers matter less than the concurrency model, the deployment shape, the ecosystem you inherit, and the team that will maintain the service for the next three years. A practical comparison starts with those, and treats speed as one factor among several.&lt;/p&gt;

&lt;p&gt;The concurrency model is the deepest difference, and it shapes how code is written every day. Go has goroutines: lightweight threads managed by the runtime, multiplexed onto a small number of operating system threads. A goroutine costs a few kilobytes of stack, so a service can run tens of thousands of them without strain. Communication between goroutines happens through channels, and the language makes it natural to write a handler that spawns work, waits for it, and times out cleanly. The code below is the shape of a Go handler that fans out to two dependencies in parallel and returns whichever result is needed, with a timeout that bounds the whole operation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"context"&lt;/span&gt;
    &lt;span class="s2"&gt;"encoding/json"&lt;/span&gt;
    &lt;span class="s2"&gt;"net/http"&lt;/span&gt;
    &lt;span class="s2"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Name&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="sb"&gt;`json:"name"`&lt;/span&gt;
    &lt;span class="nc"&gt;Orders&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;   &lt;span class="sb"&gt;`json:"orders"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;
    &lt;span class="n"&gt;userCh&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;orderCh&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&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;userCh&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s2"&gt;"Ayesha Khan"&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;go&lt;/span&gt; &lt;span class="k"&gt;func&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;orderCh&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="mi"&gt;14&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;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;userCh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;orderCh&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Done&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="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Err&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="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&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="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;fetchProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"upstream timeout"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StatusGatewayTimeout&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="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Header&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="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewEncoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&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;Java's answer changed fundamentally with virtual threads, introduced in Java 21 through Project Loom. A virtual thread is also lightweight, also cheap to create in large numbers, and it runs on a carrier thread managed by the JVM. The difference is that existing Java code, written in the familiar blocking style, gets the benefit without being rewritten. A method that blocks on a database call or an HTTP request simply parks its virtual thread instead of blocking an operating system thread, and the code reads like ordinary sequential Java. The example below does the same fan out as the Go handler, using a structured executor that waits for both tasks and cancels the rest on failure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StructuredTaskScope&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfileService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&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;int&lt;/span&gt; &lt;span class="n"&gt;orders&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;public&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt; &lt;span class="nf"&gt;fetchProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StructuredTaskScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ShutdownOnFailure&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="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;userTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fork&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;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Ayesha Khan"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;orderTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fork&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;gt;&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&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;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;throwIfFailed&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&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;orderTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&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="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;The two models converge in practice. Go asks you to write concurrent code explicitly, with channels and context, and the compiler and the runtime make that cheap. Java with virtual threads lets you write straightforward blocking code and gets scalability from the runtime. A Go developer will say the explicit model is easier to reason about. A Java developer will say the blocking model is easier to read. Both are right, and the choice is mostly about which style your team writes well. The old criticism that Java cannot handle high concurrency without reactive programming is outdated, and any comparison that still makes it is describing Java 8, not Java 21.&lt;/p&gt;

&lt;p&gt;Startup time and memory are the second difference, and they matter most in specific deployments. A Go service compiles to a single static binary that starts in milliseconds and uses tens of megabytes of memory. That shape is ideal for serverless functions, for short lived jobs, for edge deployments, and for containers where you want a small image and a fast cold start. A Java service starts a JVM, loads classes, warms up the just in time compiler, and settles into a larger memory footprint, often hundreds of megabytes. That cost is paid once per process start, and it is irrelevant for a long running service, but it is real for a function that starts on every request. Modern JVMs have narrowed the gap with ahead of time compilation and class data sharing, but Go still wins this category clearly. If your deployment starts processes often, that matters. If your service runs for weeks, it does not.&lt;/p&gt;

&lt;p&gt;Throughput and latency are closer than either community likes to admit. For a typical API that spends most of its time waiting on a database, the language is rarely the bottleneck. Both runtimes will saturate the database long before they saturate the CPU. For compute heavy work, the JVM's just in time compiler is excellent, and a hot Java method can match or beat equivalent Go code, because the JVM has decades of optimization behind it and it profiles the actual workload at runtime. Go's compiler is simpler and produces predictable performance without warmup, which is an advantage for latency sensitive services that cannot afford a warmup period. The honest way to decide is to benchmark your own workload: the same endpoints, the same database, the same load pattern, measured with latency percentiles rather than a single throughput number. A benchmark that does not resemble your traffic is marketing, not evidence.&lt;/p&gt;

&lt;p&gt;The ecosystem difference is about what you inherit. Java has Spring Boot, which is the most complete backend framework in any language: dependency injection, data access, security, validation, messaging, scheduling, and observability, all integrated and documented, with an answer for almost every problem a backend team will face. The cost is complexity and magic. A Spring Boot application does a great deal at startup, and understanding what it did requires understanding the framework, not just your code. Go has a small standard library that covers HTTP servers, JSON, and concurrency, and a set of focused libraries for the rest: a router, an ORM, a database driver. The cost is assembly. A Go team writes more glue code, chooses its own libraries, and owns the integration. Spring Boot gives you a framework to learn. Go gives you pieces to assemble. Teams that value a paved road and a large hiring pool choose Spring Boot. Teams that value a small binary, explicit behavior, and fast builds choose Go.&lt;/p&gt;

&lt;p&gt;Error handling is a cultural difference that shows up in every code review. Go returns errors as values, and the caller decides what to do. The pattern is verbose, and it is deliberate: every failure is visible at the call site, and there is no hidden control flow. Java uses exceptions, which separate the normal path from the error path and let an error propagate to a handler far from where it happened. Exceptions are concise, and they are also easy to misuse: a caught and swallowed exception hides a failure, and an unchecked exception can travel further than anyone intended. Neither model is objectively better. Go's model forces you to confront errors, which is good for reliability and tedious to write. Java's model keeps the code clean, which is good for readability and risky when exceptions are handled carelessly. A team's discipline matters more than the language's mechanism.&lt;/p&gt;

&lt;p&gt;Hiring and maintenance are the factors that decide more projects than any technical argument. Java developers are plentiful, Spring Boot experience is common, and a Java service can be handed to a new team with a reasonable expectation that they will understand it. Go developers are fewer, but Go codebases tend to be smaller and more uniform, because the language leaves less room for stylistic divergence. A Go service is often easier for a new developer to read end to end, because there is less framework to learn before the business logic becomes visible. Both languages are safe long term choices. Java has been the enterprise default for decades, and Go has been the cloud native default for more than a decade. Neither is going away, and neither will strand your team.&lt;/p&gt;

&lt;p&gt;The deployment story follows from the binary. A Go service ships as one file, copies into a scratch or distroless container image, and runs with no runtime to install. A Java service ships as a jar, runs on a JVM image, and needs memory tuning for the heap and the garbage collector. Modern garbage collectors, particularly ZGC, have made Java's pause times small and predictable, but the tuning still exists, and a team that has never tuned a JVM will spend time learning it. The Go garbage collector is simpler to operate and harder to tune badly, which is a genuine operational advantage for a small team without a JVM specialist.&lt;/p&gt;

&lt;p&gt;So which one should you pick? The decision tree is short. Pick Go when the service is a small to medium API, when it starts often, when the team is small, when the deployment is containers or serverless, and when the service spends its time doing I/O rather than heavy computation. Pick Java when the system is large and long lived, when the team is large, when Spring Boot's ecosystem covers problems you would otherwise build yourself, when the organization already hires Java developers, and when the service needs the JVM's mature libraries for messaging, batch processing, or enterprise integration. Many organizations run both, with Go for edge services and Java for the core platform, and that is a reasonable architecture rather than a failure to decide.&lt;/p&gt;

&lt;p&gt;The worst reason to pick either one is fashion. Go is not better because it is newer, and Java is not better because it is established. Both languages will happily run your service, and both will punish the same mistakes: no timeouts, no backpressure, no observability, and a database used as a queue. Pick the language your team writes well, that fits your deployment, and that hires easily in your market, and then spend the energy you saved on the problems that actually determine whether the service survives production. The language is the least interesting part of a backend system that works, and the most debated part of one that does not.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>go</category>
      <category>backend</category>
    </item>
    <item>
      <title>Running Local LLMs in Production with Ollama</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Fri, 20 Nov 2026 13:13:37 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/running-local-llms-in-production-with-ollama-32ol</link>
      <guid>https://dev.to/mubashirtaj/running-local-llms-in-production-with-ollama-32ol</guid>
      <description>&lt;p&gt;Running a large language model on your own hardware used to be a research project. You needed to understand quantization, manage GPU memory by hand, and write inference code against a low level library. Ollama changed the shape of that work. It packages models, serves them behind a simple HTTP API, and handles the details of loading, caching, and unloading on one machine. The interesting question is no longer whether you can run a model locally. It is whether you should run it in production, and what production means when the model is a process on a server you own rather than an API key for someone else's service.&lt;/p&gt;

&lt;p&gt;The reasons to run locally are concrete. The first is privacy. Prompts and documents never leave your infrastructure, which matters for customer data, internal documents, and regulated industries where sending text to a third party API is not an option. The second is cost at steady volume. A hosted API charges per token, and the bill grows with every request. A local GPU has a fixed cost, and once you have paid for the hardware, a thousand extra requests cost almost nothing except electricity. The third is latency and availability. A local model answers in tens of milliseconds of network time, because the network is a local socket, and it keeps working when the internet connection does not. The fourth is control. You choose the model, the version, and the quantization, and no provider update changes your behavior overnight.&lt;/p&gt;

&lt;p&gt;The reasons not to run locally are equally concrete. A hosted API gives you the largest and most capable models, updated constantly, with no hardware to buy or maintain. A local setup gives you smaller models, which are less capable at reasoning, long context, and edge cases. A local GPU is a single point of failure that you must monitor, cool, and replace. A hosted API scales to a spike in traffic without you doing anything, while a local server saturates and queues. The honest framing is that local models are right for high volume, well understood tasks where privacy or cost matters, and hosted APIs are right for tasks where capability matters most. Many production systems use both, with the local model handling the routine work and the hosted model handling the hard cases.&lt;/p&gt;

&lt;p&gt;Model selection starts with quantization, which is the tradeoff that determines everything else. A model is a set of weights, and quantization stores those weights with fewer bits. A 7 billion parameter model at 16 bit precision needs about 14 gigabytes of memory. The same model quantized to 4 bits needs about 4 gigabytes, and it runs on a consumer GPU or even a good CPU. The cost is a small loss in quality, which is acceptable for many tasks and unacceptable for some. Ollama models are distributed pre quantized, with names that encode the size and the quantization, so picking a model is really picking a point on the quality versus resource curve. Start with a small model, measure it on your real prompts, and only move to a larger one when the small one fails in a way you can describe.&lt;/p&gt;

&lt;p&gt;Getting started is deliberately simple. Install Ollama, pull a model, and it is serving on localhost. The commands below are the whole setup, and the simplicity is part of the appeal: there is no cluster to configure and no deployment pipeline to build for the first version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama pull llama3.1:8b
ollama run llama3.1:8b &lt;span class="s2"&gt;"Explain what a database index is in two sentences."&lt;/span&gt;
curl http://localhost:11434/api/tags
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The API is the interface your application will actually use, and it is worth learning directly rather than through a wrapper. The generate endpoint takes a prompt and returns a response, and the chat endpoint takes a list of messages with roles, which is the right shape for a conversational feature. Both endpoints support streaming, which is important for user experience: a response that streams token by token feels fast even when the total time is the same, because the user sees the first words immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:11434/api/chat -d &lt;span class="s1"&gt;'{
  "model": "llama3.1:8b",
  "messages": [
    { "role": "system", "content": "You are a helpful support assistant. Answer briefly." },
    { "role": "user", "content": "How do I reset my password?" }
  ],
  "stream": false
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Streaming is a separate concern from generation, and the application code should handle it explicitly. The code below calls the chat endpoint from Go, reads the streamed response line by line, and prints each token as it arrives. The important detail is that the response body is a stream of JSON objects, one per token, and the client must read it incrementally rather than waiting for the whole body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"bufio"&lt;/span&gt;
    &lt;span class="s2"&gt;"bytes"&lt;/span&gt;
    &lt;span class="s2"&gt;"encoding/json"&lt;/span&gt;
    &lt;span class="s2"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s2"&gt;"net/http"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;chatRequest&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Model&lt;/span&gt;    &lt;span class="kt"&gt;string&lt;/span&gt;      &lt;span class="sb"&gt;`json:"model"`&lt;/span&gt;
    &lt;span class="nc"&gt;Messages&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;chatMsg&lt;/span&gt;   &lt;span class="sb"&gt;`json:"messages"`&lt;/span&gt;
    &lt;span class="nc"&gt;Stream&lt;/span&gt;   &lt;span class="kt"&gt;bool&lt;/span&gt;        &lt;span class="sb"&gt;`json:"stream"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;chatMsg&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Role&lt;/span&gt;    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="sb"&gt;`json:"role"`&lt;/span&gt;
    &lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="sb"&gt;`json:"content"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;chatChunk&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Message&lt;/span&gt; &lt;span class="n"&gt;chatMsg&lt;/span&gt; &lt;span class="sb"&gt;`json:"message"`&lt;/span&gt;
    &lt;span class="nc"&gt;Done&lt;/span&gt;    &lt;span class="kt"&gt;bool&lt;/span&gt;    &lt;span class="sb"&gt;`json:"done"`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;main&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;reqBody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Marshal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chatRequest&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="s2"&gt;"llama3.1:8b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Messages&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;chatMsg&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Explain connection pooling in two sentences."&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="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:11434/api/chat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reqBody&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;scanner&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;bufio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewScanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;make&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="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Scan&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;var&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt; &lt;span class="n"&gt;chatChunk&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Unmarshal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Bytes&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;amp;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Done&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Println&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;The scanner buffer line deserves attention. The default scanner buffer is small, and a long token or a long line can exceed it, which silently stops the stream. Setting an explicit buffer is the kind of detail that separates a demo from a production client, and it is exactly the kind of detail that only shows up under real load.&lt;/p&gt;

&lt;p&gt;Production operation starts with the questions that have nothing to do with the model. How many requests can one server handle at once? Ollama loads a model into memory, and concurrent requests share it, but each request needs its own context window, which consumes memory and compute. The number of parallel requests is limited by GPU memory and by the context size you configure. A server that handles ten concurrent short prompts may handle only two concurrent long ones. Measure the concurrency on your hardware with your prompts, and set a limit in your application or your load balancer so that the eleventh request waits in a queue with a clear timeout instead of degrading all ten.&lt;/p&gt;

&lt;p&gt;Health checking and monitoring are the next layer. Ollama exposes the list of running models and the version endpoint, and your health check should verify that the model you need is actually loaded, not just that the process is alive. A process that is running but has evicted your model will answer every request with a slow cold load, and a health check that only checks the port will miss it. Metrics to track are time to first token, total generation time, tokens per second, queue depth, and GPU memory use. Time to first token is the metric your users feel, because it determines how long they wait before anything appears on screen.&lt;/p&gt;

&lt;p&gt;Security is often an afterthought in local setups, and it should not be. Ollama binds to localhost by default, and that default is correct. The moment you expose it on a network, anyone who can reach it can use your GPU, read your prompts, and run any model you have installed. If a service on another host needs access, put a reverse proxy in front of it with authentication, and never expose the Ollama port directly to the internet. The same rule applies to any internal tool: the API has no authentication of its own, so the network boundary and the proxy are the security.&lt;/p&gt;

&lt;p&gt;Retrieval augmented generation, usually called RAG, is the pattern that makes a local model useful for your own data. The model itself does not know your documentation, your tickets, or your product. A RAG system stores embeddings of your documents in a vector store, retrieves the relevant chunks for each question, and includes them in the prompt. Ollama serves embedding models as well as chat models, so the same server can produce the embeddings and answer the questions. RAG quality depends far more on retrieval than on the model: if the retrieved chunks are wrong, even a perfect model gives a wrong answer. Spend effort on chunking, the retrieval query, and evaluation, not on chasing a slightly larger model.&lt;/p&gt;

&lt;p&gt;Evaluation is the discipline that keeps a local model honest. A hosted model comes with a reputation, but a local model comes with a choice you made, and that choice needs evidence. Build a set of prompts that represent your real workload, with expected answers or at least expected properties, and run them against every model and every quantization you consider. Check for factual accuracy, for format compliance, and for the failure modes that matter in your product, such as inventing a link or a function that does not exist. Re run the evaluation when you change the model, the prompt, or the retrieval step, because each of those changes can move the results.&lt;/p&gt;

&lt;p&gt;The deployment shape that works for most teams is simple: one Ollama server per GPU machine, behind a reverse proxy, with your application calling it over HTTP. If you need more capacity, add more machines and load balance across them, and keep the model list identical on each one so any server can answer any request. If you need high availability, run at least two servers, because a single GPU machine is a single point of failure with a real mean time to repair. Kubernetes can manage this, but it is not required. A plain server with systemd, monitoring, and a runbook is a legitimate production setup, and it is simpler to debug than a GPU operator in a cluster you do not fully understand.&lt;/p&gt;

&lt;p&gt;The decision to run local models is ultimately about control versus capability. You gain privacy, predictable cost, and independence from a provider. You accept smaller models and hardware to operate. For summarization, classification, extraction, and question answering over your own documents, a local model is often more than good enough, and the privacy and cost advantages are decisive.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Service Mesh: Istio vs Linkerd, and Do You Need One</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Thu, 19 Nov 2026 13:14:10 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/service-mesh-istio-vs-linkerd-and-do-you-need-one-oj8</link>
      <guid>https://dev.to/mubashirtaj/service-mesh-istio-vs-linkerd-and-do-you-need-one-oj8</guid>
      <description>&lt;p&gt;A service mesh is one of those technologies that is easy to adopt for the wrong reasons. The pitch is compelling: mutual TLS between every service, traffic splitting, retries, observability, and policy enforcement, all without changing application code. The reality is a second distributed system running alongside your first one, with its own control plane, its own proxies, its own failure modes, and its own upgrade cycle. The decision is not really Istio versus Linkerd. The decision is whether you need a mesh at all, and if you do, which set of tradeoffs fits the size and shape of your system. Getting the first question wrong makes the second one irrelevant.&lt;/p&gt;

&lt;p&gt;A service mesh has two parts. The data plane is a proxy that runs next to every service instance, usually as a sidecar container in the same pod. Every request a service makes passes through its proxy, and every request it receives passes through the proxy too. The proxy can encrypt the traffic, add headers, enforce timeouts, retry failures, and record metrics, all without the application knowing. The control plane is the central brain that configures those proxies: it distributes certificates, pushes routing rules, and collects telemetry. The split matters because the data plane is what your requests depend on at runtime, while the control plane is what you depend on when you change something. A control plane outage should not stop traffic, because the proxies keep running with their last known configuration. A proxy failure, on the other hand, stops traffic for that pod immediately, which is why proxy reliability is the first thing to evaluate.&lt;/p&gt;

&lt;p&gt;The problem a mesh solves is real. In a system with dozens of services, each service needs to know how to find the others, how to encrypt the connection, how to retry a failure, and how to report what happened. Without a mesh, every team reimplements that logic in its own language and library, and the implementations drift. One service retries aggressively, another never retries, a third has a timeout of thirty seconds on an endpoint that should fail in two. A mesh moves those decisions out of application code and into shared configuration, so the behavior is consistent and the platform team can change it without redeploying every service. That consistency is the value. The mesh is not a performance optimization. It is an organizational tool for managing behavior across many services owned by many teams.&lt;/p&gt;

&lt;p&gt;Istio is the most capable mesh, and also the most complex. Its data plane is Envoy, a powerful proxy that can do almost anything: advanced routing, rate limiting, fault injection, WebAssembly extensions, and fine grained policy. Its control plane, istiod, manages certificates, configuration, and service discovery. Istio supports multiple clusters, multiple networks, and gateways for traffic entering and leaving the mesh. It also has the largest ecosystem and the most documentation, which matters when something goes wrong at night. The cost of that capability is operational weight. Istio has many configuration resources, many ways to do the same thing, and a learning curve that is steep for a small team. Upgrades need planning, and a misconfigured resource can break traffic in ways that are hard to diagnose without understanding the whole model.&lt;/p&gt;

&lt;p&gt;Linkerd takes the opposite approach. It is deliberately small and opinionated. Its proxies are written in Rust, use very little memory, and start fast. Its control plane is simpler, its configuration surface is smaller, and its defaults are chosen for you rather than presented as a menu. Linkerd does the core jobs well: mutual TLS by default, golden metrics for every service, traffic splitting, and retries with budgets. It does less than Istio, and that is the point. A team that adopts Linkerd is buying simplicity and accepting limits. A team that needs advanced traffic policy, multi cluster federation, or deep Envoy extensibility will hit Linkerd's ceiling and wish they had chosen Istio, or wish they had not chosen a mesh at all.&lt;/p&gt;

&lt;p&gt;The resource difference is worth measuring rather than guessing. An Envoy sidecar typically uses tens of megabytes of memory and a meaningful slice of CPU under load. A Linkerd proxy uses a few megabytes and much less CPU. Multiply that by the number of pods in your cluster, and the difference becomes real money and real scheduling pressure. The latency added by a proxy hop is small for both, usually well under a millisecond, but it applies twice per request: once leaving the caller and once entering the receiver. For a request that crosses five services, that is ten proxy hops.&lt;/p&gt;

&lt;p&gt;Mutual TLS is the feature most teams cite first, and it deserves a careful look. A mesh gives every service an identity in the form of a certificate, and every connection is authenticated and encrypted. That is a genuine security improvement over plaintext traffic inside a cluster, and it is hard to build correctly by hand across many languages. But mutual TLS is not a complete security story. It proves the caller is a workload in your cluster, not that the caller is allowed to perform the requested action. Istio has rich authorization policy for this. Linkerd has simpler policy support, and it is still maturing. Either way, enabling mutual TLS without authorization policy gives you encryption without access control, which is better than nothing and worse than a complete solution.&lt;/p&gt;

&lt;p&gt;Traffic management is the second feature teams actually use. A mesh can shift a percentage of traffic to a new version, run a canary, and roll back by changing configuration rather than redeploying anything. It can add retries with budgets, so a failing downstream is not hammered by every caller retrying at once, and it can set timeouts per route. These are powerful tools, but they are also tools that can be implemented without a mesh. A canary can be done with two Deployments and a Service that selects both, weighted by replica counts. Retries and timeouts can be set in a good HTTP client library. The mesh makes these things easier and more uniform, but it is not the only way to get them.&lt;/p&gt;

&lt;p&gt;Before adopting either mesh, there is a decision tree worth walking through honestly. First, how many services do you have? If the answer is fewer than ten, a mesh is almost certainly premature. An ingress controller, a good HTTP client with timeouts and retries, and TLS at the edge cover the real needs, and the operational cost of a mesh buys nothing. Second, how many teams own those services? A mesh earns its keep when many teams need consistent behavior and a platform team can own the mesh as a product. One team with five services can coordinate in a chat message. Third, do you have a compliance or security requirement that demands encrypted service to service traffic with identity? If yes, that requirement alone can justify a mesh, and it is the strongest justification there is. Fourth, do you already run Kubernetes well? A mesh on top of a cluster that is itself unstable adds a second layer of debugging to every incident.&lt;/p&gt;

&lt;p&gt;If the answers point to a mesh, the choice between Istio and Linkerd comes down to scale and ambition. Choose Istio when you need its feature set: multiple clusters, advanced traffic policy, egress control, and a large community. Choose Linkerd when you want the core mesh features with the smallest operational burden, and you are willing to accept its limits. The installation experience reflects the difference. Both install with a single command in a test cluster, and both have health checks to verify the installation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;istioctl install --set &lt;span class="nv"&gt;profile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;default -y
kubectl get pods -n istio-system
linkerd check --pre
linkerd install &lt;span class="o"&gt;|&lt;/span&gt; kubectl apply -f -
linkerd check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commands are easy. The hard part is everything after installation: upgrading, debugging a proxy that refuses a connection, and understanding why a routing rule did not apply. That hard part is smaller with Linkerd and larger with Istio, which is exactly the tradeoff you are choosing.&lt;/p&gt;

&lt;p&gt;The configuration that most teams touch first is mutual TLS, and the shape of it shows the difference in philosophy. The resource below enables strict mutual TLS for a namespace, and it is mostly maps rather than lists, which makes it easy to read and to review in a pull request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;security.istio.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;PeerAuthentication&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;mtls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;STRICT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strict mode means plaintext traffic is rejected, so every service in the namespace must be part of the mesh before you turn it on. The safe rollout is permissive mode first, which accepts both plaintext and mutual TLS, then strict mode once the metrics show all traffic is encrypted. Skipping the permissive step is the most common way teams break their own services during adoption, and it is entirely avoidable.&lt;/p&gt;

&lt;p&gt;There is also a middle path that many teams should consider seriously: adopt the observability and the practices without the mesh. Golden metrics for every service can come from a good metrics setup and consistent instrumentation. Retries and timeouts can come from a shared client library or a framework default. Traffic splitting can come from the ingress controller or the deployment tool. This middle path is often the right answer for a team with ten to twenty services that does not yet need multi cluster routing or strict identity based policy.&lt;/p&gt;

&lt;p&gt;The honest summary is that a service mesh is a bet on organizational scale. It pays off when you have enough services and enough teams that shared behavior, shared identity, and shared observability are worth a permanent platform investment. It does not pay off when you have a handful of services and a problem that a library or an ingress rule would solve. Between Istio and Linkerd, Istio is the choice for breadth and Linkerd is the choice for simplicity, and the right answer depends on which of those your team can actually operate. Install one in a staging cluster, break it deliberately, and see how long it takes your team to diagnose the failure. That experiment will tell you more than any comparison article, because the mesh you can debug is the mesh you can run.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>kubernetes</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How Airbnb Handles Millions of Bookings Without Double-Booking a Home</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:15:19 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/how-airbnb-handles-millions-of-bookings-without-double-booking-a-home-2fjd</link>
      <guid>https://dev.to/mubashirtaj/how-airbnb-handles-millions-of-bookings-without-double-booking-a-home-2fjd</guid>
      <description>&lt;p&gt;A double booking is the worst failure a marketplace like Airbnb can have. Two guests pay for the same home on the same nights, one of them arrives to find someone else in the living room, and the trust that the whole business runs on is damaged in a way no refund fully repairs. Preventing it sounds like a simple database constraint, but at the scale of millions of listings and millions of bookings, it is a distributed systems problem with real tradeoffs. The design has to answer three questions: how to check availability fast enough for search, how to make the booking itself atomic, and what to do when two people try to book the same nights at the same moment.&lt;/p&gt;

&lt;p&gt;The first idea is that availability is not a single boolean. A listing has a calendar, and each night has a state: available, booked, blocked by the host, or unavailable because of a minimum stay or a check in rule. Search needs to answer a different question from booking. Search asks which listings are available for a date range, across millions of listings, in well under a second. Booking asks whether this specific listing is still available for these exact nights, right now. Those two questions are served by two different systems, and confusing them is the most common design mistake.&lt;/p&gt;

&lt;p&gt;Search reads from an index, not from the transactional database. When a host blocks a date or a booking completes, an event updates the search index, and the listing disappears from results for those nights. The index is eventually consistent, which means a listing can appear available in search for a short time after it has actually been booked. That is acceptable for search, because search results are a suggestion, not a promise. The promise is made at booking time, against the database, where consistency is strict. A system that tried to make search strictly consistent would be slow and fragile, and it would still need the booking time check anyway.&lt;/p&gt;

&lt;p&gt;The booking itself is a transaction, and the transaction is the heart of the design. A booking touches several things at once: it must verify the nights are free, mark them as booked, create the reservation record, place a hold on the payment, and notify the host. If any step fails, all of them must be undone, and the nights must become available again. In a relational database, this is a single transaction with a lock on the rows that represent the listing's calendar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;night&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;availability&lt;/span&gt;
 &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;listing_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;
   &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;night&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-20'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-23'&lt;/span&gt;
   &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'available'&lt;/span&gt;
 &lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- If the query returns fewer than 4 rows, a night is&lt;/span&gt;
&lt;span class="c1"&gt;-- already booked or blocked, so roll back and tell&lt;/span&gt;
&lt;span class="c1"&gt;-- the guest the dates are no longer available.&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listing_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;guest_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check_in&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check_out&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="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;77&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-20'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-24'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pending_payment'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;availability&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'booked'&lt;/span&gt;
 &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;listing_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;
   &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;night&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-20'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="s1"&gt;'2026-12-23'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SELECT FOR UPDATE is the mechanism that makes the whole thing safe. It takes a row level lock on the availability rows for those nights, and any other transaction trying to book the same nights blocks until the first one commits or rolls back. The second transaction then sees the updated status and fails the availability check. There is no window in which two bookings can both succeed, because the lock serializes them. The lock is held only for the duration of a short transaction, so contention is limited to the rare case where two people book the same listing on the same nights at the same moment, which is exactly the case that needs serializing.&lt;/p&gt;

&lt;p&gt;A lock in the database is not the only option, and the alternatives are worth understanding because they show up in other systems. Optimistic locking adds a version number to the listing or the calendar, reads it at the start, and fails the write if the version changed before commit. It performs better under low contention and worse under high contention, because conflicting transactions retry instead of waiting. A distributed lock in Redis or a similar store can serialize bookings across services, but it adds a failure mode: if the lock holder crashes, the lock must expire, and the expiry window has to be handled carefully. The database lock is the simplest correct answer for a single database, and it is usually the right starting point. A service should only move to a more complex mechanism when it can measure a real problem with the simple one.&lt;/p&gt;

&lt;p&gt;Payment adds a second phase to the booking, and the design has to handle the gap between reserving the nights and charging the guest. Airbnb does not charge the full amount the instant the guest clicks book. The booking is created in a pending state, the payment is authorized, and the reservation is confirmed once the authorization succeeds. If the authorization fails, the transaction rolls back and the nights are released. If the guest's browser closes or the network drops in the middle, the pending reservation must not hold the nights forever. Pending reservations have a short expiry, often measured in minutes, and a background job releases the nights when the expiry passes. This is the same pattern as a seat hold in ticketing, and the expiry is what keeps a failed payment from blocking a listing for hours.&lt;/p&gt;

&lt;p&gt;Idempotency is what makes retries safe, and retries are constant in a system like this. A guest on a slow connection presses the book button twice, a mobile app retries a request that timed out, a load balancer replays a request after a gateway restart. Every one of those retries must produce the same single reservation. The client generates an idempotency key when the booking flow starts, sends it with the request, and the server stores it with the reservation. A second request with the same key returns the original reservation instead of creating a new one. The key is stored in the same transaction as the reservation, so there is no window where the reservation exists but the key does not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nc"&gt;CreateBooking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="nc"&gt;BookingRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Reservation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BeginTx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rollback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;existingID&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;QueryRowContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sb"&gt;`SELECT reservation_id FROM idempotency_keys WHERE key = $1`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IdempotencyKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;existingID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;loadReservation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;existingID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;bookNights&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ExecContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sb"&gt;`INSERT INTO idempotency_keys (key, reservation_id) VALUES ($1, $2)`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IdempotencyKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Commit&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;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The handler above returns the existing reservation when it sees a repeated key, which means the client can retry as aggressively as it wants without creating duplicates. Notice that the idempotency check, the booking, and the key insert all happen inside one transaction. Splitting them across separate calls would open a race where two identical requests both pass the check before either one writes the key.&lt;/p&gt;

&lt;p&gt;Calendar sync is the problem that makes this harder than a single database can solve. Hosts list the same property on multiple platforms, and a booking on another platform must block the dates on Airbnb, and vice versa. Airbnb imports and exports iCalendar feeds for this, and it polls those feeds on a schedule. Polling means there is a delay, sometimes minutes, between a booking elsewhere and the calendar updating. During that window, a double booking is possible, and no database lock can prevent it, because the other platform's booking never touches Airbnb's database. The mitigation is operational rather than technical: hosts who sync calendars see a warning about the delay, and the support team handles the rare conflicts with rebooking and compensation. Some problems are not solved by engineering alone, and admitting that is part of good design.&lt;/p&gt;

&lt;p&gt;Pricing adds another layer of state that interacts with availability. Nightly prices change with demand, weekends, seasons, and host rules, and the price a guest sees in search must match the price at checkout. The booking flow therefore re-reads the price inside the same transaction that checks availability, and if the price changed since search, the guest sees the new price and confirms again. Showing a stale price and then charging a different one is a trust problem, and it is cheaper to re-confirm than to handle the complaints.&lt;/p&gt;

&lt;p&gt;The failure modes worth planning for are specific. A database failover during a booking can leave the client unsure whether the booking succeeded, which is why the client retries with the same idempotency key and the server answers from the stored key. A payment authorization that succeeds but whose response is lost must not create a paid booking without a reservation, which is why the reservation and the payment record are created together and reconciled by a background job. A host who cancels after confirmation triggers a different flow entirely: the guest is rebooked, the host is penalized, and the listing's reputation takes the hit, because the marketplace cannot allow hosts to treat confirmed bookings as optional.&lt;/p&gt;

&lt;p&gt;The lesson for a backend engineer is that a booking system is a state machine with a small number of states and strict transitions, and the database is the enforcer. Availability is a set of rows with a status, booking is a locked transaction that flips them, payment is a pending state with an expiry, and retries are safe because of idempotency keys. The search index, the calendar sync, and the notifications are all secondary systems that feed into the transaction but never replace it. Build the transaction first, test it with concurrent bookings for the same nights, and only then build the features around it. A marketplace earns trust by never selling the same night twice, and the way it earns that trust is a lock, a transaction, and a key.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>backend</category>
      <category>programming</category>
    </item>
    <item>
      <title>Docker vs Podman: Picking Your Container Runtime</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:14:41 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/docker-vs-podman-picking-your-container-runtime-2c28</link>
      <guid>https://dev.to/mubashirtaj/docker-vs-podman-picking-your-container-runtime-2c28</guid>
      <description>&lt;p&gt;Docker and Podman run the same containers, from the same images, built from the same Dockerfiles, and a developer who knows one can use the other in an afternoon. The differences are not in what they run, but in how they run it: the architecture around the container, the security model, and the tooling that surrounds day to day work. Picking between them is really a question about your environment. A solo developer on a laptop, a team running CI pipelines, and a company operating Linux servers in production will weigh the same facts differently, and each of them can make a reasonable choice that is different from the others.&lt;/p&gt;

&lt;p&gt;The core difference is the daemon. Docker runs a background daemon, dockerd, that owns the containers. The docker command line is a client that talks to that daemon over a socket. Every container on the host is a child of that daemon process, and the daemon usually runs as root. Podman has no daemon. The podman command talks directly to the container runtime, and each container is a child of the process that started it, usually in the user's own session. This is not a cosmetic difference. It changes the failure modes, the security model, and how the runtime fits into the rest of the system.&lt;/p&gt;

&lt;p&gt;A daemon is a single point of failure and a single point of control. If dockerd crashes or is restarted, every container it manages is affected, and restarts are coordinated through the daemon. A daemon also makes the architecture simple to reason about: one service owns all container state, and remote management is natural because the client and the daemon already communicate over an API. Podman trades that central control for a simpler process model. If you start a container from your shell, it is your process. If you start it from systemd, systemd owns it, supervises it, and restarts it according to the unit file. There is no extra process in the middle to fail or to upgrade.&lt;/p&gt;

&lt;p&gt;The security difference follows directly from the daemon. Because dockerd runs as root, anyone who can talk to the Docker socket effectively has root on the host. Mounting the Docker socket into a container, or giving a developer access to it, is equivalent to giving them root, because they can start a privileged container with the host filesystem mounted. This is a well known risk, and it is the reason CI systems that expose the Docker socket are a common source of escapes. Docker has a rootless mode that addresses this, but it is an add on configuration rather than the default, and it requires extra setup.&lt;/p&gt;

&lt;p&gt;Podman was designed rootless from the start. A normal user can run containers without sudo, and those containers run inside the user's own user namespace, so a process that escapes the container still only has the privileges of that user. User namespaces map the root user inside the container to an unprivileged user outside it, which closes the most dangerous escape path. This is the strongest reason to pick Podman for a shared development server or a CI runner, where untrusted code routinely runs in containers. The same Dockerfile that builds a root owned image in Docker builds the same image in Podman, and the difference is only in who owns the running process.&lt;/p&gt;

&lt;p&gt;For day to day use, the commands are deliberately similar. Podman aliases most Docker commands, and many teams set up a docker alias to podman so existing scripts keep working. The differences show up at the edges: networking, volumes, and orchestration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;podman run --rm -p 8080:8080 myapp:latest
podman ps
podman logs -f myapp
podman build -t myapp:latest .
podman image ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A container started this way behaves the same as it would under Docker, and the flags are the same because both tools implement the same OCI runtime specification. The image format is the same too. A Dockerfile written for Docker builds under Podman with no changes, and an image pushed to a registry by one tool can be pulled by the other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; golang:1.25 AS build
&lt;span class="k"&gt;WORKDIR&lt;/span&gt; /app
&lt;span class="k"&gt;COPY&lt;/span&gt; go.mod go.sum ./
&lt;span class="k"&gt;RUN&lt;/span&gt; go mod download
&lt;span class="k"&gt;COPY&lt;/span&gt; . .
&lt;span class="k"&gt;RUN&lt;/span&gt; &lt;span class="nv"&gt;CGO_ENABLED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 go build -o server ./cmd/server

&lt;span class="k"&gt;FROM&lt;/span&gt; gcr.io/distroless/static-debian12
&lt;span class="k"&gt;COPY&lt;/span&gt; --from=build /app/server /server
&lt;span class="k"&gt;USER&lt;/span&gt; nonroot
&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 8080
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/server"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multi stage builds work identically, and the distroless final image keeps the runtime small and free of a shell. One detail worth noting is the USER instruction. An image that runs as root by default is a habit worth breaking regardless of runtime, and both tools respect the instruction the same way.&lt;/p&gt;

&lt;p&gt;The gap between the tools is widest in orchestration. Docker Compose is the standard way to run a multi container application on one host, and it is mature, widely documented, and understood by every developer who has worked with containers. Podman supports Compose through podman compose, and it also supports a native alternative called Quadlet, which generates systemd units from simple container definition files. A Quadlet file describes a container the way a systemd unit describes a service, and systemd then manages its lifecycle, restarts, and logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;My&lt;/span&gt; &lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;
&lt;span class="na"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;online&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;span class="na"&gt;Wants&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;online&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;

&lt;span class="k"&gt;[Container]&lt;/span&gt;
&lt;span class="na"&gt;Image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;myapp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;latest&lt;/span&gt;
&lt;span class="na"&gt;PublishPort&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//db:5432/app&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Restart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;always&lt;/span&gt;

&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;multi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file lives in the systemd directory, and the container starts on boot, restarts on failure, and logs to the journal, with no extra tooling. For a single host running a handful of services, this is often simpler than a Compose file plus a separate process manager. For a development environment with many interdependent services that change often, Compose is usually the more comfortable tool, and it works with Podman too, so the choice is not forced.&lt;/p&gt;

&lt;p&gt;Networking is the other area where the two diverge in practice. Docker creates a bridge network by default and containers on it can reach each other by name. Podman does the same, and it also offers pasta and slirp4netns networking for rootless containers, which lets an unprivileged user publish ports without special setup. The default rootless networking in Podman has historically been slower for high throughput workloads, because packets pass through userspace. For a development machine or a small API server this rarely matters. For a production workload pushing serious network traffic, measure it rather than assuming either direction.&lt;/p&gt;

&lt;p&gt;Kubernetes is where the distinction mostly disappears. Both Docker and Podman are clients for local development, and neither of them runs your production cluster. Kubernetes uses a container runtime such as containerd or CRI-O underneath, and it does not care which tool built the image. A team can develop with Podman on laptops, build images in CI with either tool, and deploy the same images to Kubernetes without any of those decisions leaking into the cluster. The runtime choice is a local and CI concern, not a production architecture decision, unless your production servers run containers directly on the host.&lt;/p&gt;

&lt;p&gt;So how should you choose? Start with the constraints that are hardest to change. If your team already runs Docker, your CI is built around it, and your developers know it, switching to Podman buys little. The cost of retraining and retooling outweighs the architectural benefit for most teams. If you are starting fresh on Linux, or if your CI runs untrusted code, or if you want containers managed by systemd on servers, Podman is the better default. It is the safer choice on a shared host, and its daemonless model removes a class of failures.&lt;/p&gt;

&lt;p&gt;If you develop on macOS or Windows, the calculus changes again. Docker Desktop is a polished product with a graphical interface, integrated Kubernetes, and extension support, and it is the path of least resistance on those platforms. Podman Desktop exists and has improved quickly, and it is free for commercial use, which matters for teams that hit Docker Desktop licensing terms. Try both on your own machine before deciding for a team, because the quality of the desktop experience is something you feel every day.&lt;/p&gt;

&lt;p&gt;The migration path is low risk either way. Images are portable, Dockerfiles are portable, and the command line is nearly identical. The practical approach is to try Podman on one machine or one CI runner for a week, keep Docker where it already works, and compare the real experience: rootless operation, systemd integration, and startup behavior. A runtime is infrastructure, and infrastructure decisions should be made on evidence from your own workload, not on enthusiasm for an architecture diagram. Pick the one that fits your operating system, your security requirements, and your team's habits, and revisit the decision when those change.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>docker</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GraphQL vs REST: Picking Your API Style</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Sat, 14 Nov 2026 13:15:01 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/graphql-vs-rest-picking-your-api-style-f90</link>
      <guid>https://dev.to/mubashirtaj/graphql-vs-rest-picking-your-api-style-f90</guid>
      <description>&lt;p&gt;Every backend team reaches the same fork in the road eventually. The API needs to serve a web client, a mobile client, and maybe a third party integration, and the question becomes whether to build REST endpoints or a GraphQL schema. Both are legitimate. Both have shipped systems at enormous scale. The argument that one of them is simply better misses the point. The real question is which set of tradeoffs fits the clients you actually have.&lt;/p&gt;

&lt;p&gt;REST is the older style, and its shape is familiar. Resources live at URLs, HTTP verbs describe the operation, and each endpoint returns a fixed shape. A request to get a user looks like this, and the server decides exactly what comes back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ayesha Khan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ayesha@example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"avatarUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://cdn.example.com/avatars/42.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"createdAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2025-03-14T09:12:00Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"lastLoginAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-10T18:02:11Z"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That fixed shape is both the strength and the weakness of REST. It is easy to cache, easy to reason about, and easy to document. It is also the source of the two classic problems: over fetching and under fetching. A mobile client that only needs a user's name and avatar receives the whole record, including fields it will never render. A client that needs a user and their recent orders makes one request for the user, then another for the orders, then another for each order's items, because no single endpoint returns the nested shape it wants. The first problem wastes bandwidth. The second problem, the N plus 1 request pattern on the client side, wastes round trips, and on a mobile connection round trips are the expensive part.&lt;/p&gt;

&lt;p&gt;GraphQL attacks exactly those two problems by letting the client describe the shape it wants. One endpoint receives a query, and the response contains exactly the fields requested, nested as deeply as the client asked. The same user request becomes this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;user&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="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;
    &lt;span class="n"&gt;avatarUrl&lt;/span&gt;
    &lt;span class="nf"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;id&lt;/span&gt;
      &lt;span class="n"&gt;total&lt;/span&gt;
      &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;productName&lt;/span&gt;
        &lt;span class="n"&gt;quantity&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response contains the name, the avatar, and five orders with their items, and nothing else. No extra fields, no extra requests. For a client that renders a dashboard with data from five different resources, the difference is dramatic: one request replaces five, and the payload is exactly the data on screen. That is why teams with complex frontends, especially mobile teams on slow networks, often reach for GraphQL first.&lt;/p&gt;

&lt;p&gt;The cost of that flexibility is paid on the server side, and it is worth pricing honestly. A REST endpoint has one code path per resource, and its cost is visible. A GraphQL schema has resolvers, and a naive resolver design recreates the N plus 1 problem inside the server. The query above asks for five orders and the items inside each one. If the order resolver loads orders with one query and then each order's items trigger a separate query, the server runs six queries for one request, and a deeper query can run hundreds. The standard fix is batching, usually with a DataLoader, which collects the item requests for all five orders and loads them in one query.&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="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;DataLoader&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'dataloader'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;itemsByOrderId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataLoader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;orderIds&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="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="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'SELECT * FROM order_items WHERE order_id = ANY($1)'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;orderIds&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;orderIds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;id&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="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Inside the order resolver:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;itemsByOrderId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Caching is the second server side cost, and it is the one teams underestimate most. REST responses are cacheable by URL, which means CDNs, proxies, and browsers all understand them. GraphQL sends every query to the same endpoint, usually as a POST, so the entire HTTP caching layer stops working. The workarounds exist: persisted queries that turn common operations into GET requests, response caching keyed on the query, and CDN support for GraphQL, but each one is machinery you have to build and maintain. If your API serves mostly public, cacheable data to many anonymous clients, REST gives you a CDN for free. GraphQL makes you earn it.&lt;/p&gt;

&lt;p&gt;Versioning is where the two styles diverge philosophically. REST versions with URLs or headers: version one lives at /v1/, version two at /v2/, and old clients keep working until you retire the version. GraphQL has no versions. Fields are added to the schema and old fields are deprecated but kept, so the schema only grows. The GraphQL argument is that additive evolution avoids the maintenance burden of multiple versions. That is true when the team is disciplined about never removing fields. It becomes a different burden when the schema accumulates five years of deprecated fields that nobody dares to delete because some client somewhere still asks for them. Schema governance, field usage tracking, and a real deprecation policy are not optional in a GraphQL codebase. They are the versioning system, wearing different clothes.&lt;/p&gt;

&lt;p&gt;Security is also different, not easier. A REST endpoint exposes one resource, so its cost is bounded and its authorization check is local. A GraphQL endpoint exposes the whole graph, so a single query can be expensive in ways that are hard to predict. A malicious or careless client can ask for a user, their orders, the items in each order, the reviews of each item, and the users who wrote those reviews, nesting deeper until the server is doing thousands of queries for one request. The defenses are query complexity analysis, depth limits, timeouts, and per field authorization, but all of them are configuration you must write. REST gets most of this for free from its shape. GraphQL requires you to build it.&lt;/p&gt;

&lt;p&gt;There is a third option that deserves a mention, because the debate is often framed as a binary and it is not. A REST API can adopt the parts of GraphQL that solve real pain without adopting the whole system. Field selection through query parameters, sparse fieldsets like /users?fields=name,avatarUrl, and an endpoint that accepts a batch of resource requests are all cheap to add and solve most over fetching and under fetching. Conversely, a GraphQL API can sit in front of REST services internally, acting as an aggregation layer for the frontend while the services behind it stay simple. The aggregation pattern is common at scale: the public API is a GraphQL gateway, and the internal services are REST, each owned by one team.&lt;/p&gt;

&lt;p&gt;So how do you choose? Start with the clients. If you have one web client and one mobile client with similar needs, REST is usually the simpler choice, and the simplicity compounds: simpler caching, simpler authorization, simpler debugging, simpler onboarding for new developers. If you have many clients with genuinely different data needs, a mobile app on unreliable networks, or a frontend team that is blocked waiting for backend endpoints to be built, GraphQL pays for itself quickly. The deciding question is whether the client shapes vary enough that a fixed endpoint shape is the bottleneck. If the answer is no, GraphQL is machinery in search of a problem.&lt;/p&gt;

&lt;p&gt;A practical rule that survives contact with real projects: do not pick GraphQL because it is fashionable, and do not pick REST because it is familiar. Pick the one whose costs land where your team is strong. If your team is good at caching, schema governance, and resolver performance, GraphQL's costs are manageable and its client flexibility is real. If your team is small and the API surface is narrow, REST's simplicity is a feature, not a limitation. And whichever you choose, keep the boundary clean: one public style, documented well, with the other style used internally only where it earns its place. An API that is half REST and half GraphQL with no reason for the split is worse than either one done properly.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>api</category>
      <category>backend</category>
    </item>
    <item>
      <title>Vector Databases: How Similarity Search Actually Works</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Fri, 13 Nov 2026 13:14:07 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/vector-databases-how-similarity-search-actually-works-2pki</link>
      <guid>https://dev.to/mubashirtaj/vector-databases-how-similarity-search-actually-works-2pki</guid>
      <description>&lt;p&gt;Search used to mean matching words. You typed a keyword, the database looked for that keyword in an index, and the results were the rows that contained it. That model works well when you know the exact words you are looking for. It fails the moment the question is about meaning instead of spelling. A document about "feline behavior" contains no word "cat" in the title, but it is exactly what a search for "cats" should return. Vector databases exist to close that gap. They search by meaning, and understanding how they do it starts with understanding embeddings.&lt;/p&gt;

&lt;p&gt;An embedding is a list of numbers, usually a few hundred to a few thousand long, that represents the meaning of a piece of text, an image, or an audio clip. A model such as a transformer reads the input and produces the vector. The key property is geometric: inputs with similar meaning produce vectors that point in similar directions. The numbers themselves are not human readable, and that is fine, because nobody reads them directly. What matters is the geometry. Two vectors close together mean two inputs that mean similar things. Two vectors far apart mean the opposite.&lt;/p&gt;

&lt;p&gt;Similarity between two vectors is usually measured with cosine similarity, which is the cosine of the angle between them. Vectors pointing in the same direction score near 1. Vectors at right angles score near 0. Vectors pointing in opposite directions score near negative 1. The formula is simple, and implementing it in a few lines makes the idea concrete.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linalg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;norm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linalg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;norm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&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;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;feline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;feline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# close to 1, similar meaning&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# close to 0, unrelated meaning&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other distance measures exist, and the choice is worth a sentence each. Euclidean distance measures straight line distance between vector endpoints, which is sensitive to magnitude as well as direction. Dot product is fast and common when vectors are normalized, because for unit vectors it equals cosine similarity. Most systems normalize embeddings to unit length at insert time, which makes the three measures behave consistently and keeps the math cheap. The important decision is to pick one measure and use it consistently across inserts and queries, because a database that stores vectors measured one way and queries them another way returns nonsense.&lt;/p&gt;

&lt;p&gt;The obvious search algorithm is brute force: compare the query vector against every stored vector and keep the top matches. That is exact, and it is also unusable at scale. A million vectors of 768 dimensions means roughly 768 million multiply operations per query, and the cost grows linearly with the collection. This is the problem vector databases solve. They trade a small amount of accuracy for a large amount of speed, using approximate nearest neighbor search, usually shortened to ANN.&lt;/p&gt;

&lt;p&gt;The two index families you will meet most often are IVF and HNSW, and they take opposite approaches to the same tradeoff. IVF, inverted file index, clusters the vectors into groups at build time, using k-means or a similar algorithm. At query time it finds the clusters nearest to the query vector and only searches inside those. Searching ten clusters out of a thousand skips ninety nine percent of the work, at the cost of possibly missing a vector that sits just across a cluster boundary. The number of clusters probed is a tuning knob: probe more for accuracy, probe fewer for speed.&lt;/p&gt;

&lt;p&gt;HNSW, hierarchical navigable small world, builds a graph instead. Each vector is a node, connected to its nearest neighbors, and the graph is layered so that the top layers are sparse and the bottom layer contains every node. A query starts at the top layer and greedily walks toward the query vector, dropping down a layer each time it gets closer. It is like navigating a map by zooming in: the top layer gets you to the right city, the next layer to the right neighborhood, the bottom layer to the right street. HNSW is usually faster and more accurate than IVF for the same memory, and it is the default in most systems today, including pgvector. The tradeoff is build time and memory, because the graph has to be constructed and held in memory.&lt;/p&gt;

&lt;p&gt;The storage question is where the market gets interesting. A dedicated vector database such as Pinecone, Weaviate, or Qdrant is built around ANN search from the ground up. A general purpose database with a vector extension, most famously PostgreSQL with pgvector, adds vector search to a database you already run. The practical difference is less about raw search speed than about what else you need. If your application already lives in Postgres, and your vector collection is in the hundreds of thousands rather than the hundreds of millions, pgvector keeps your data in one place, in one transaction, with one backup strategy. A minimal example shows how little ceremony it takes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="no"&gt;EXTENSION&lt;/span&gt; &lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="kt"&gt;vector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&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;content&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&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;embedding&lt;/span&gt; &lt;span class="kt"&gt;vector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;768&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;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt;
&lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="n"&gt;hnsw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;embedding&lt;/span&gt; &lt;span class="n"&gt;vector_cosine_ops&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;embedding&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'[0.9, 0.1, 0.8, ...]'&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;=&amp;gt;&lt;/code&gt; operator is cosine distance, and the HNSW index makes that query fast without scanning the whole table. The pattern is the same everywhere: store the vector beside the metadata, filter by the metadata with ordinary SQL, and rank by vector distance. That combination, metadata filtering plus vector ranking, is what real applications need. A pure vector store that cannot filter by tenant id or date forces you to do that filtering in application code, which defeats the purpose.&lt;/p&gt;

&lt;p&gt;The most common application today is retrieval augmented generation, or RAG. The pattern is straightforward. Documents are split into chunks, each chunk is embedded and stored, a user question is embedded the same way, the nearest chunks are retrieved, and those chunks are passed to a language model along with the question. The model answers from the retrieved context instead of from memory alone. The vector database is the memory of the system, and its quality determines the quality of the answers. Bad chunking, stale embeddings, or a missing metadata filter will produce confident answers built on the wrong documents, and no amount of prompt engineering fixes that.&lt;/p&gt;

&lt;p&gt;Chunking deserves more attention than it usually gets, because it is where most RAG systems quietly fail. A chunk that is too large dilutes the meaning: one paragraph about refunds buried in a page about everything else will match weakly. A chunk that is too small loses context: a sentence that says "it costs fifty dollars" is useless without knowing what "it" is. A common starting point is chunks of a few hundred tokens with a small overlap between neighbors, and then measuring retrieval quality on real questions instead of guessing. Overlap matters because meaning does not respect chunk boundaries, and a sentence split in half embeds badly on both sides.&lt;/p&gt;

&lt;p&gt;There are real limits to know before adopting the technology. Embeddings drift: when the embedding model is upgraded, old vectors are not comparable with new ones, and the honest fix is re-embedding the collection, which is a batch job worth planning for. High dimensional indexes are approximate by design, so recall is never one hundred percent, and systems that need exact results should keep a brute force path for small collections. Memory is a cost driver: an HNSW graph for a hundred million vectors needs serious RAM, and that cost is the reason many teams keep vectors in Postgres until the collection outgrows it. None of these are reasons to avoid vector search. They are reasons to size the solution to the collection you actually have.&lt;/p&gt;

&lt;p&gt;A good starting rule is simple. If you already run Postgres and your collection is under a few million vectors, start with pgvector. You get transactions, backups, and filtering for free, and you can migrate later if the collection outgrows it. If you need multi tenancy at huge scale, managed infrastructure, or hybrid search that combines keyword and vector ranking natively, a dedicated vector database is the better home. Either way, measure recall on your own data. Two systems with the same index can return different results on different data, and the benchmark that matters is your questions against your documents.&lt;/p&gt;

&lt;p&gt;Vector search is not magic, and that is good news. It is geometry applied to meaning, with an index that trades a little accuracy for a lot of speed. Once you see the embedding, the distance metric, and the index as three separate decisions, the whole field becomes approachable, and picking a database becomes a sizing question instead of a leap of faith.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>database</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GitOps with ArgoCD: Pull-Based Deploys Explained</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:13:56 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/gitops-with-argocd-pull-based-deploys-explained-2mo</link>
      <guid>https://dev.to/mubashirtaj/gitops-with-argocd-pull-based-deploys-explained-2mo</guid>
      <description>&lt;p&gt;Most deployment pipelines push. A CI job builds an image, then runs a command that reaches into the cluster and applies it. That works until the day it does not, and the failure modes are familiar: a deploy script that only exists on one person's laptop, a kubectl command run from the wrong terminal, a cluster state that no longer matches anything written down anywhere. GitOps replaces the push with a pull. The cluster watches a Git repository and makes itself match what the repository says. The deploy is no longer an action someone performs. It is a state the system converges toward.&lt;/p&gt;

&lt;p&gt;The definition is simple enough to state in one sentence. Git is the single source of truth for the desired state of the system, and an automated agent inside the cluster continuously reconciles the live state with that desired state. Everything else in GitOps follows from that sentence. If a change is not in Git, it is not a real change. If a change is in Git, it will reach the cluster without anyone running a deploy command.&lt;/p&gt;

&lt;p&gt;ArgoCD is the most widely used implementation of that idea for Kubernetes, and it helps to understand what it actually does before reaching for its configuration. ArgoCD runs inside your cluster as a set of controllers. Its Application controller watches the repositories you register and the Application resources you define. For each application it compares two things: the manifests rendered from Git, and the live resources currently in the cluster. When they differ, the application is out of sync, and ArgoCD can either report that fact or fix it, depending on the sync policy you chose. That comparison loop is the whole product. Everything else, the UI, the CLI, the API, is a way of looking at the loop or steering it.&lt;/p&gt;

&lt;p&gt;The first concept to get right is the Application resource. It is a small Kubernetes custom resource that tells ArgoCD three things: where the desired state lives, what it should be applied to, and how strictly to enforce it. Here is a minimal example that deploys a service from a Helm chart stored in Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argoproj.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Application&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;checkout-api&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argocd&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
  &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;repoURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://github.com/example/platform.git&lt;/span&gt;
    &lt;span class="na"&gt;targetRevision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/checkout-api&lt;/span&gt;
  &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://kubernetes.default.svc&lt;/span&gt;
    &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;checkout&lt;/span&gt;
  &lt;span class="na"&gt;syncPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;automated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;prune&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="na"&gt;selfHeal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each field carries a decision. The source points at a repository, a branch, and a path inside it, so the desired state is a specific directory at a specific revision. The destination names the cluster and namespace. The sync policy says what ArgoCD should do when it finds drift. With automated sync enabled, a commit to main is enough to trigger a deploy. With prune enabled, resources that were deleted from Git are deleted from the cluster. With self heal enabled, a manual change made directly in the cluster is reverted on the next reconciliation. Those last two options are what turn ArgoCD from a deployment tool into a guarantee: the cluster cannot quietly drift away from the repository.&lt;/p&gt;

&lt;p&gt;This pull model changes the security picture in a useful way. In a push model, the CI system needs credentials that can write to the cluster, which means the credentials for production live in the same system that runs untrusted pull request builds. In a pull model, the cluster reaches out to Git and pulls. The CI system only needs permission to write to a Git repository, which is a far smaller blast radius. The cluster's credentials never leave the cluster. This is one of the strongest practical arguments for GitOps, and it is independent of any tooling preference. It follows from the direction of the connection.&lt;/p&gt;

&lt;p&gt;The second concept is the separation between the application code repository and the configuration repository. A common beginner mistake is to put Kubernetes manifests in the same repository as the application source and let CI update image tags there. That works, but it mixes two concerns with different review rules and different owners. The cleaner pattern is two repositories, or at least two clearly separated directories with different ownership. The application repository holds source code and a CI pipeline that builds and publishes an image. The configuration repository holds manifests, and the only thing CI writes into it is the new image tag. A deploy is therefore a small, reviewable commit that changes one line in one file, and the full history of what ran in production is the Git history of that repository. Rollback becomes a revert, which is a workflow every developer already knows.&lt;/p&gt;

&lt;p&gt;The third concept is the app of apps pattern, which solves the problem of managing ArgoCD itself with GitOps. If every application is defined by an Application resource, then those resources can themselves live in a Git repository, managed by a single parent Application. The parent watches a directory of Application manifests and creates the children. Adding a new service to the platform becomes a pull request that adds one file to that directory. This is how teams scale from three applications to three hundred without the ArgoCD configuration becoming a manual chore. The bootstrap problem, how the first Application gets created, is solved once by hand, and everything after that is declarative.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argoproj.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Application&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;root-apps&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argocd&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
  &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;repoURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://github.com/example/platform.git&lt;/span&gt;
    &lt;span class="na"&gt;targetRevision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argocd/apps&lt;/span&gt;
  &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://kubernetes.default.svc&lt;/span&gt;
    &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;argocd&lt;/span&gt;
  &lt;span class="na"&gt;syncPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;automated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;prune&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="na"&gt;selfHeal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A question that comes up immediately is secrets. Git is a terrible place for plaintext secrets, and GitOps does not change that. The standard answers are Sealed Secrets, which encrypt secrets into the repository so only a controller in the cluster can decrypt them, or the External Secrets Operator, which keeps secrets in a vault and syncs them into the cluster at runtime. Either way the rule is the same: the repository holds a reference to a secret, never the secret itself. Teams that ignore this rule usually discover the problem when a repository becomes public or a contractor gains read access, and by then the rotation work is painful. Decide the secrets strategy before the first application goes live, not after.&lt;/p&gt;

&lt;p&gt;Drift detection deserves a closer look, because it is where GitOps earns its keep in day to day operations. Someone will, at some point, run kubectl edit against a production deployment to test a quick fix and forget to revert it. In a push model that change lives on silently until the next deploy overwrites it or, worse, until nobody remembers it existed. With self heal enabled, ArgoCD notices the difference within minutes and reverts it, and the event is visible in the ArgoCD UI and in its logs. The manual change is not punished. It is simply not durable. That property makes the cluster boring in the best sense: the live state is always explainable from the repository, and an incident review can start from Git history instead of from guesswork.&lt;/p&gt;

&lt;p&gt;Environments are the next natural question. The usual approach is one directory per environment, with a shared base and per environment overlays, using Kustomize or Helm values. A staging directory points at the same charts with different replicas, resource limits, and configuration values. Promotion from staging to production is a pull request that copies the tested image tag from one directory to another, which gives you a review step and an audit trail for free. Avoid the temptation to give each environment its own branch. Branches drift apart and merge conflicts in YAML are miserable. One branch, multiple directories, is the pattern that survives contact with a real team.&lt;/p&gt;

&lt;p&gt;There are limits, and honest coverage of them matters. GitOps is a poor fit for state that is inherently dynamic, like database migrations that must run exactly once in order, or secrets that rotate on their own schedule. ArgoCD has sync hooks and waves for ordering, and tools like Argo Rollouts add progressive delivery, but a migration that needs a human decision is better handled outside the sync loop. GitOps is also not a substitute for observability. Knowing that the cluster matches Git tells you nothing about whether the application is healthy. Pair ArgoCD with monitoring and alerting, and treat a sync failure as a page worthy event, not a UI badge to glance at later.&lt;/p&gt;

&lt;p&gt;Getting started is deliberately small. Install ArgoCD in a test cluster, register one repository, create one Application with manual sync first, and watch the comparison view until you trust what it reports. Then enable automated sync, add prune and self heal, and move one low risk service to the pull model. The team will learn the workflow from that one service: change the manifest, open a pull request, get a review, merge, watch the sync. After a week of that, expanding to the rest of the platform is a mechanical exercise, because the hard part was never the tool. It was agreeing that Git is the truth, and then letting the cluster enforce it.&lt;/p&gt;

&lt;p&gt;The payoff is quiet but real. Deploys stop being events that need a runbook and a war room. They become commits. Rollbacks become reverts. The question "what is running in production right now?" stops being a research project and becomes a git log command. That is what pull based deploys buy you, and ArgoCD is a solid, proven way to get there.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>kubernetes</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How YouTube Handles a Billion Hours of Video</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Wed, 11 Nov 2026 13:14:10 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/how-youtube-handles-a-billion-hours-of-video-47aj</link>
      <guid>https://dev.to/mubashirtaj/how-youtube-handles-a-billion-hours-of-video-47aj</guid>
      <description>&lt;p&gt;Every day, people watch more than a billion hours of video on YouTube. That number is hard to picture, so here is a smaller one: more than 500 hours of video are uploaded every minute. The system has to accept that flood, convert every upload into a dozen playable formats, store it forever, and deliver it instantly to a phone on a slow connection in one country and a television on fiber in another, all while deciding which video to recommend next. The interesting part is not any single piece of that. It is how the pieces fit together so that no one part becomes a bottleneck that takes the rest down with it.&lt;/p&gt;

&lt;p&gt;Start with the upload, because everything downstream depends on a decision made in the first seconds. When a creator uploads a video, YouTube does not store the file as it arrived and serve it directly. The uploaded file might be a 4K master of several gigabytes, recorded with settings no browser can play efficiently. The system first stores that original in a durable object store, as the source of truth, and then hands it to a transcoding pipeline. Transcoding converts the original into many versions: different resolutions from 144p to 4K, different bitrates, and different codecs. A phone on a weak connection gets a small 360p stream. A television gets 4K. The viewer never sees this. They press play and the player picks the version that fits their connection right now, and switches versions mid playback if the connection changes.&lt;/p&gt;

&lt;p&gt;Transcoding at YouTube's scale cannot be a single queue with a single pool of workers. The pipeline is a distributed job system. An upload creates a job, the job is split into chunks, and those chunks are processed in parallel across many machines. A short video might transcode in seconds. A two hour upload in 4K takes longer, and the system shows the creator a progress state rather than blocking on completion. The important design choice is that upload, transcode, and publish are separate stages with a queue between each pair. If transcoding slows down, uploads keep working, and videos already transcoded keep publishing. A failure in one stage does not cascade into the others.&lt;/p&gt;

&lt;p&gt;Storage is the next problem, and it is bigger than it looks. YouTube stores exabytes of video, and the copies multiply fast: one original, plus a dozen transcoded versions, plus thumbnails, plus the metadata that describes them all. No single database and no single filesystem holds that. The storage layer is a distributed object store built for this shape: huge files, written once, read millions of times, rarely deleted. Files are split into chunks, and each chunk is replicated across machines in different racks and different data centers. A disk failure, a rack failure, even a data center failure does not lose a video, because another copy is elsewhere. Hot videos, the ones millions of people are watching right now, are also copied into caching layers closer to viewers, so the origin storage is not hit for every play.&lt;/p&gt;

&lt;p&gt;Delivery is where the system earns its reputation, and the mechanism is a content delivery network of unusual scale. YouTube runs its own global edge network, with caching servers in thousands of locations. When you press play, the video does not stream from a central server. It streams from an edge cache near you, and if that cache does not have the segment yet, it fetches it from a parent cache, which fetches it from origin. Video is delivered in small segments, typically a few seconds each, over HTTP. That segmentation is what makes adaptive bitrate work. The player downloads one segment at a time, measures how fast it arrived, and picks the quality of the next segment accordingly. A dip in your connection means the next segment is lower quality, not a frozen video. The player also buffers a few segments ahead, so a brief stall in the network is invisible.&lt;/p&gt;

&lt;p&gt;Metadata is a separate system from video storage, and that separation is deliberate. The title, description, tags, view count, comments, and the channel it belongs to live in databases optimized for reads and writes of small records, not in the object store with the video bytes. This matters because the read patterns are completely different. Video bytes are read sequentially, in large chunks, by a small number of viewers per file at a time. Metadata is read constantly, by everyone, for search, recommendations, and the watch page. Mixing the two workloads in one store would make both slower.&lt;/p&gt;

&lt;p&gt;The view count is a good example of how the system trades exactness for scale. A video with a hundred million views cannot update a single counter row on every play. That would be a write hotspot, one row that every viewer in the world tries to update at once. Instead, views are counted in shards and aggregated. The number you see is close to exact, and exactness within a small margin is fine for a view count. The system applies the same thinking to likes and comments: aggregate, approximate where the product allows it, and reserve strong consistency for the things that genuinely need it, like whether a video is public, private, or deleted.&lt;/p&gt;

&lt;p&gt;Search and recommendations deserve their own mention, because they are the reason people stay on the site. Search is a separate indexing pipeline. When a video is published, its title, description, tags, and captions are indexed, along with signals like watch time and engagement. A search query hits that index, not the storage layer, and returns ranked results in milliseconds. Recommendations work differently. They are built from models that predict what a viewer is likely to watch next, based on watch history, what similar viewers watched, and the video's own performance with audiences like this one. The models are trained offline on enormous datasets and served from a separate system that can answer a ranking request in tens of milliseconds. The watch page you see is the output of that ranking, rendered from metadata, not a query against the video store.&lt;/p&gt;

&lt;p&gt;The database story behind all of this is worth a closer look, because YouTube is one of the best known users of a pattern called sharding with a twist. The system uses a globally distributed database that can scale horizontally across data centers while still offering strong consistency where it matters. A video's metadata lives on a shard determined by its id, and a read for that video goes to the shard that owns it. That keeps any single database from becoming a bottleneck. The lesson for smaller systems is not to copy the database. It is to notice the pattern: identify the unit of sharding early, keep related data together on one shard where you can, and never design a feature that requires a cross shard transaction on the hot path.&lt;/p&gt;

&lt;p&gt;Live streaming adds a different set of pressures. A live video cannot be transcoded in advance, because it does not exist yet. The ingest server receives the stream, transcodes it in near real time into several quality levels, and pushes the segments to the edge as they are produced. Latency becomes a product decision. The default mode buffers a few seconds for stability. A low latency mode trades some of that buffer for a delay closer to two seconds, which matters for live chat and interaction. The tradeoff is explicit, and the system lets the creator choose, because there is no single right answer.&lt;/p&gt;

&lt;p&gt;There is a temptation to read all of this and conclude that YouTube's architecture is out of reach, and in its full form it is. But the patterns inside it are ordinary engineering, applied with discipline. Separate the hot path from the cold path. Put a queue between stages so one slow stage does not block the rest. Store the original and derive the rest. Deliver from the edge, in small segments, and let the client adapt. Shard by a stable key, and aggregate counters instead of updating one row. Keep metadata and bulk data in different stores, because they have different access patterns. These are decisions any team can make at any scale, and they are what make a system survive growth instead of collapsing under it.&lt;/p&gt;

&lt;p&gt;If you are building something that handles media, start with the smallest version of this shape. Accept an upload, store the original, and transcode it asynchronously with a job queue. Serve the result through a CDN, even a small one, and let the player adapt to the connection. Put the metadata in a database and the bytes in object storage, and keep them separate from the start. That separation is the decision that is hardest to retrofit later, and it is the one YouTube's design gets right first. The billion hours are impressive. The architecture that survives them is the lesson.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>systemdesign</category>
      <category>backend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Monolith vs Microservices: When Splitting Helps and When It Hurts</title>
      <dc:creator>Mubashir Taj</dc:creator>
      <pubDate>Tue, 10 Nov 2026 13:15:06 +0000</pubDate>
      <link>https://dev.to/mubashirtaj/monolith-vs-microservices-when-splitting-helps-and-when-it-hurts-2j7h</link>
      <guid>https://dev.to/mubashirtaj/monolith-vs-microservices-when-splitting-helps-and-when-it-hurts-2j7h</guid>
      <description>&lt;p&gt;Few architecture debates generate as much confident bad advice as monolith versus microservices. Ask a room of developers and you will hear two certainties that contradict each other: that a monolith is technical debt waiting to happen, and that microservices are needless complexity. Both claims are wrong in the same way. They treat the question as a matter of taste, when it is actually a matter of fit. The right architecture depends on the team, the domain, and the stage of the product. The same split that saves one organization will sink another.&lt;/p&gt;

&lt;p&gt;Start with what each shape actually is, because the words get used loosely. A monolith is a single deployable unit that contains the whole application: the web layer, the business logic, and usually the data access, all in one codebase and one process. A microservices architecture splits the application into many small services, each independently deployable, each owning its own data, communicating over the network. The difference that matters most is not size. It is the boundary between the pieces. In a monolith, a call between two modules is a function call: fast, type checked, and easy to trace. In microservices, that same call crosses a network, which means latency, serialization, partial failure, and versioning. Everything else follows from that one fact.&lt;/p&gt;

&lt;p&gt;A monolith's strengths are real and often underrated. Development is simple. A new developer clones one repository, runs one command, and has the whole system on their machine. Refactoring is cheap, because the compiler or the test suite sees the whole codebase at once. Renaming a field touches every caller in one commit. Transactions are straightforward, because one database can guarantee that two related writes either both happen or neither does. Debugging is easier too: a stack trace shows the full path through the code, and there is no network hop to suspect. Deployment is one artifact, one version, one rollback. For a small team building a product whose shape is still changing, that simplicity is worth a great deal.&lt;/p&gt;

&lt;p&gt;The monolith's weaknesses are also real, and they appear on a schedule. As the codebase grows, the build gets slower, the test suite gets slower, and the deploy becomes scarier, because every change ships with every other change. Teams start stepping on each other: two features in the same release, one of them buggy, block the other from going out. Scaling gets blunt. If one endpoint needs ten times the capacity and the rest need none, you scale the whole application anyway, because it is one unit. And the technology choice is one choice for everything. The language and framework picked on day one are the language and framework for every feature that follows.&lt;/p&gt;

&lt;p&gt;Microservices fix those specific problems, and it is worth naming them precisely rather than praising the pattern in general. Independent deployment is the big one. A team can ship its service without coordinating a release train with five other teams. Independent scaling follows: the hot service gets more instances while the quiet ones stay small. Fault isolation is real too. If the recommendation service crashes, the checkout service keeps working, provided the two are genuinely independent and checkout does not block on recommendations. And technology can vary by service, so the team that needs a fast data pipeline can use one stack while the team that needs a simple CRUD API uses another.&lt;/p&gt;

&lt;p&gt;But every one of those benefits has a price, and the price is paid in distributed systems problems. The network is not reliable, so every call between services needs a timeout, a retry policy, and a plan for what happens when the other service is down. Data consistency gets harder in a specific way. There is no single database transaction across two services, so a business operation that used to be one atomic write becomes a saga: a sequence of steps with compensating actions when a later step fails. That is not a small change. It is a different way of thinking about correctness, and it leaks into every feature that touches more than one service.&lt;/p&gt;

&lt;p&gt;Observability gets harder too. A request that used to appear in one log file now crosses five services, each with its own logs, and reconstructing what happened requires a correlation id passed through every hop and a tracing system that collects it. Testing gets harder in the same direction. A unit test is still easy, but an integration test now needs several services running, with realistic data, in the right versions. Teams that split too early discover they have traded one hard problem, a big codebase, for several harder problems, distributed transactions, network failure modes, and cross service debugging, before they had any of the benefits that justify the trade.&lt;/p&gt;

&lt;p&gt;So when does splitting actually help? There are a few honest signals. The first is team size and independence. When several teams work on the same codebase and their releases keep colliding, splitting along team boundaries can help, because each team gets its own deploy pipeline and its own release cadence. The second is genuinely different scaling needs. A video processing pipeline and a user profile API have nothing in common in their load profile, and scaling them together wastes money. The third is fault isolation that the business actually needs. If one feature going down must not take the rest of the system with it, and the product genuinely depends on that guarantee, the isolation is worth the cost. The fourth is regulatory or security boundaries, such as payment data that must live in a separate system with separate access controls.&lt;/p&gt;

&lt;p&gt;And when does splitting hurt? Almost always when the product is young. A startup with three developers and an unproven product does not have a scaling problem. It has a learning problem, and microservices slow down learning, because every change to a boundary becomes a negotiation between services. Splitting hurts when the domain boundaries are not yet clear. If you cannot draw the lines between your services with confidence, you will draw them wrong, and a wrong service boundary is far more expensive than a wrong module boundary, because moving code between services means changing APIs, data ownership, and deployment pipelines. It hurts when the team lacks operational maturity. If you do not have good logging, tracing, alerting, and deployment automation, microservices will multiply the operational surface faster than the team can manage it.&lt;/p&gt;

&lt;p&gt;The practical middle path, and the one most teams should take, is the modular monolith. Keep one deployable application, but organize it into strict modules with clear boundaries, each module owning its own data access and exposing a narrow interface to the others. No module reaches into another module's tables. No module imports another module's internals. The boundaries are enforced by code review and by structure, not by the network. Then, if one module later needs to become a service, the extraction is a mechanical job: the interface already exists, the data ownership is already clear, and the hard design work is already done. If it never needs to become a service, you have lost nothing.&lt;/p&gt;

&lt;p&gt;The Go example below shows the shape. Two modules, orders and inventory, live in the same binary. They communicate through interfaces defined in a shared package, and neither one touches the other's storage. The day inventory needs to become a service, the implementation of the Inventory interface is replaced with an HTTP client, and the orders module does not change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;ID&lt;/span&gt;     &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;ItemID&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;Qty&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Inventory&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Reserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemID&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;qty&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;
    &lt;span class="nc"&gt;Release&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemID&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;qty&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Orders&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;inv&lt;/span&gt; &lt;span class="nc"&gt;Inventory&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nc"&gt;NewOrders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt; &lt;span class="nc"&gt;Inventory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Place&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemID&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;qty&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ord_1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ItemID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;itemID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Qty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s2"&gt;"errors"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;errOutOfStock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;New&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"out of stock"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Store&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="k"&gt;map&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="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nc"&gt;NewStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;map&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"widget"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&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;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Reserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemID&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;qty&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;itemID&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;errOutOfStock&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;itemID&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what this buys you. The orders module never sees the stock map. The only contract between the modules is the interface. Tests for orders use a fake inventory, and tests for inventory use no orders code at all. That discipline is most of what microservices promise, without any of the network.&lt;/p&gt;

&lt;p&gt;There is also a decision framework worth applying before any split. Ask four questions, and answer them with evidence, not enthusiasm. First, which teams are actually blocked by shared releases, and how often? If the answer is rarely, there is no deployment problem to solve. Second, which parts of the system have genuinely different scaling or availability needs? If the answer is none yet, there is no scaling problem to solve. Third, can you draw the service boundaries from the domain, with each service owning data that no other service needs to write? If the answer is no, the boundaries will be wrong. Fourth, does the team have the operational tooling to run many services: tracing, centralized logging, automated deploys, and alerts that a tired person can act on at 3 in the morning? If the answer is no, fix that first, because splitting without it is how you build a system nobody can debug.&lt;/p&gt;

&lt;p&gt;A final warning about the most common failure mode. Teams split a monolith because it feels slow and messy, but the mess was never about the deployment shape. It was about unclear module boundaries, shared mutable state, and code that any part of the system could touch. Splitting that codebase into services does not fix the mess. It distributes it across a network, where it becomes harder to see and harder to fix. The order of work matters: clean up the boundaries inside the monolith first. If the monolith is still slow after that, the split will be easy, because the boundaries are already drawn. If it is fast enough after that, you have saved yourself a distributed system you did not need.&lt;/p&gt;

&lt;p&gt;The question was never monolith or microservices. It was: what problem are you solving, and is a network boundary the cheapest way to solve it? Answer that honestly, and the architecture mostly picks itself.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>microservices</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
