<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Venkatesh Vinayakarao on Medium]]></title>
        <description><![CDATA[Stories by Venkatesh Vinayakarao on Medium]]></description>
        <link>https://medium.com/@vvtesh?source=rss-cc54ba238ec8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*G4fsU5rX4WqfIKyeqm7r8g.jpeg</url>
            <title>Stories by Venkatesh Vinayakarao on Medium</title>
            <link>https://medium.com/@vvtesh?source=rss-cc54ba238ec8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 08:29:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vvtesh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Redis Lock]]></title>
            <link>https://medium.com/search-it/redis-lock-2ee304810f5a?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ee304810f5a</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sat, 23 Aug 2025 05:49:18 GMT</pubDate>
            <atom:updated>2025-08-23T05:49:18.931Z</atom:updated>
            <content:encoded><![CDATA[<p>The case of search document update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMxccNck6j9qflUHBJuHgw.png" /></figure><p>In a distributed microservices architecture, multiple services might need to update a single document in a shared search index, such as Elasticsearch or Solr. This scenario presents a classic <strong>race condition</strong>: if two services attempt to update the same document concurrently, the final state of the document can be inconsistent or incomplete, as one service’s changes may overwrite the other’s. To prevent this, a Redis-based distributed lock can be used as a coordination mechanism. By acquiring a lock on a specific document before updating it, a service can guarantee exclusive access, ensuring data integrity and a consistent final state in the search index. This process of locking, updating, and then releasing the lock is a critical pattern for maintaining a reliable search system.</p><h3>Acquire the Lock for Document Indexing</h3><p>When a service needs to update a document in a search index, it must first acquire a distributed lock using Redis. This ensures that no other service can simultaneously modify the same document.</p><p><strong>Example Redis Command:</strong> SET lock:documents:doc_1 service_A_uuid_456 NX PX 5000</p><p>The key for the lock should be unique to the seat, for example:lock:documents:doc_1. The value should be a unique identifier for the user or the request, like a session ID or a UUID. This is crucial for safely releasing the lock later. The NX (NotExists) option ensures the command only succeeds if the key does not already exist. This is what makes the command atomic and prevents multiple users from acquiring the lock on the same seat at the same time. The FX option sets an expiration time on the key. This is a built-in “release” mechanism in case the client fails to release the lock, preventing a permanent lock-up.</p><p>If the command returns OK, the lock is acquired, and the service can proceed with the update. If it returns (nil), another service has the lock, and the current request should wait or retry later.</p><h3>Update the Document in the Search Index</h3><p>After successfully acquiring the lock, the service performs the critical operation.</p><ul><li><strong>Read</strong>: The service reads the latest version of the document from the search index.</li><li><strong>Modify</strong>: It applies the necessary changes to the document.</li><li><strong>Write</strong>: The service writes the updated document back to the search index, overwriting the old version.</li></ul><h3>Release the Lock</h3><p>Once the update is complete, the lock must be released to allow other services to access the document. It’s crucial to release the lock safely to prevent one service from accidentally releasing a lock held by another.</p><ul><li><strong>Method</strong>: Use a <strong>Redis Lua script</strong> to perform a conditional deletion. This ensures the deletion is an atomic operation.</li><li><strong>Script Logic</strong>: The script checks if the value of the key matches the unique identifier set by the current service. If it matches, it deletes the key; otherwise, it does nothing.</li></ul><pre>if redis.call(&quot;get&quot;, KEYS[1]) == ARGV[1]<br>then<br>    return redis.call(&quot;del&quot;, KEYS[1])<br>else<br>    return 0<br>end</pre><p>The script ensures that even if another service’s lock expired and a new one was acquired in the meantime, the original service won’t delete the new lock, preventing a race condition.</p><p>If that master node fails immediately after and a slave is promoted, the lock may not have been replicated to the new master, allowing another client to acquire the same lock. This is the <strong>Redlock</strong> problem. A network partition can split your system into two or more segments where nodes in one segment can’t communicate with nodes in another. If a client acquires a lock and is then partitioned from the Redis server, it may believe it still holds the lock. Meanwhile, the lock on the Redis server might expire, and another client in a different network segment could acquire the same lock. This leads to two clients thinking they have exclusive access, which can cause data corruption. The idea of <strong>quorum</strong> is not used in a basic, single-instance Redis lock. A simple SET NX PX command on a single Redis server is a simple and fast solution for distributed locking, but it is not fault-tolerant. The concept of a quorum is central to more advanced and robust distributed locking algorithms built on top of Redis, such as the <strong>Redlock algorithm</strong> and <strong>Redis Sentinel</strong>. It tries to acquire the lock (SET NX PX) on each of the Redis instances. It considers the lock successfully acquired <strong>only if</strong> it gets a response from a <strong>majority (quorum)</strong> of the instances within a specific time frame. For five instances, the quorum would be at least three.</p><p>These ideas can be used in a variety of situations, even outside search.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ee304810f5a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/redis-lock-2ee304810f5a">Redis Lock</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Blob Storage to Client]]></title>
            <link>https://medium.com/search-it/from-blob-storage-to-client-b17a90956331?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b17a90956331</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[protocol]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Thu, 21 Aug 2025 15:09:18 GMT</pubDate>
            <atom:updated>2025-08-21T15:09:18.546Z</atom:updated>
            <content:encoded><![CDATA[<p>The tale of protocols</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W33AFwqe5IAP-Ss-" /><figcaption>Photo by <a href="https://unsplash.com/@alexbemore?utm_source=medium&amp;utm_medium=referral">Alexander Shatov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To stream video from blob storage (like Amazon S3, Cloudflare R2) to a client like in a service like YouTube, you can’t just send a raw video file. The process involves using specific protocols that break the video into smaller pieces and manage their delivery, a concept known as <strong>Adaptive Bitrate Streaming (ABR)</strong>. The most common protocols for this are HTTP Live Streaming (HLS) and Dynamic Adaptive Streaming over HTTP (DASH).</p><p>Here’s how these protocols work to get video chunks to the client.</p><h3>Pre-processing: The Encoding and Segmentation Pipeline</h3><p>Before a video can be streamed, it must be prepared. This is where your video chunks in blob storage come in.</p><ul><li><strong>Encoding:</strong> The raw video file is transcoded into multiple versions, or <strong>“renditions,”</strong> each with a different resolution and bitrate (e.g., 480p, 720p, 1080p). This ensures the video can be played on various devices and network conditions.</li><li><strong>Segmentation:</strong> The encoded renditions are then split into small, typically 2–6 second long, video chunks or segments.</li><li><strong>Manifest File Creation:</strong> Finally, a manifest file (like a table of contents) is created. For HLS, this is a <strong>.m3u8</strong> playlist file. For DASH, it’s a <strong>.mpd</strong> (Media Presentation Description) file. This file lists all the available video chunks, their quality levels, and their URLs. It’s the central nervous system of the video stream.</li></ul><h3>Delivery: From Blob Storage to the Client</h3><p>Once the video is prepared, the actual streaming process begins.</p><ol><li><strong>Client Request:</strong> A video player on the user’s device requests the manifest file from a server (usually a Content Delivery Network, or <strong>CDN</strong>, for global reach and faster delivery).</li><li><strong>Adaptive Streaming:</strong> The player then reads the manifest file to see which video renditions are available. It starts by requesting a video chunk from a medium-quality rendition.</li><li><strong>Real-time Adaptation:</strong> As the video plays, the client’s player continuously monitors the user’s network speed and device performance. If the connection is strong, the player requests the next chunk from a higher-quality rendition. If the connection slows down, it requests the next chunk from a lower-quality rendition to prevent buffering.</li><li><strong>HTTP-Based Delivery:</strong> Because these protocols use standard HTTP to deliver the video chunks, they can be served directly from your blob storage and easily cached by CDNs. This makes the entire process highly scalable and cost-effective.</li></ol><h3>HLS vs. DASH</h3><p>While both protocols achieve the same goal, they have some key differences:</p><ul><li><strong>HLS (HTTP Live Streaming):</strong> Developed by Apple, HLS is the most widely supported streaming protocol. It’s the de-facto standard for streaming on Apple devices (iOS, macOS).</li><li><strong>DASH (Dynamic Adaptive Streaming over HTTP):</strong> An open international standard, DASH is more flexible in its codec support. It’s natively supported by most non-Apple devices and is a popular choice for services that want broader codec compatibility.</li></ul><p>Many video streaming platforms use both protocols to ensure compatibility across a wide range of devices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b17a90956331" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/from-blob-storage-to-client-b17a90956331">From Blob Storage to Client</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Deep Dive Into Layer 4 Load Balancers]]></title>
            <link>https://medium.com/@vvtesh/a-deep-dive-into-layer-4-load-balancers-879196ec7eb5?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/879196ec7eb5</guid>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 10:07:32 GMT</pubDate>
            <atom:updated>2025-08-16T10:07:32.474Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ut-O0Zmcqh1IhsuE-HFBYg.png" /></figure><p>A <strong>Layer 4 load balancer</strong> is a type of load balancer that operates at the <strong>transport layer</strong> of the OSI (Open Systems Interconnection) model. This layer is responsible for end-to-end communication and deals with protocols like <strong>TCP</strong> and <strong>UDP</strong>.</p><p>A Layer 4 load balancer makes its routing decisions based on network-level information, such as the source and destination IP addresses and ports, without inspecting the actual content of the data packets.</p><h3>Key Characteristics</h3><ul><li><strong>Speed and Efficiency</strong>: Because it doesn’t need to inspect the packet content, a Layer 4 load balancer is generally faster and more efficient than a Layer 7 load balancer. This makes it ideal for high-volume traffic with basic distribution needs, such as DNS, gaming, or video streaming.</li><li><strong>Routing Decisions</strong>: The decisions are based on simple metrics like server load or response times. It can use algorithms like round-robin or least connections to distribute traffic.</li><li><strong>Network Address Translation (NAT)</strong>: When a request comes in, the load balancer performs NAT, changing the destination IP address from its own to that of the chosen server. Similarly, it changes the source address back to its own before forwarding the server’s response to the client.</li></ul><p>Layer 4 load balancers are effective for simple, high-performance scenarios where you need to distribute traffic quickly and efficiently.</p><p>Commercially available Layer 4 (L4) load balancers can be categorized into three main types: hardware-based appliances, software-based solutions, and cloud-native services.</p><h4>Hardware and Virtual Appliances</h4><p>These are dedicated devices or virtual machines that are deployed on-premises. They’re often used in traditional data center environments where high performance and control are critical.</p><ul><li><strong>F5 BIG-IP</strong>: A market leader, F5 offers powerful L4 and L7 load balancing solutions with a suite of advanced features for large-scale enterprise environments.</li><li><strong>Citrix ADC (formerly NetScaler)</strong>: Known for its high-performance Application Delivery Controller (ADC) features, which include L4 load balancing, traffic management, and security.</li><li><strong>A10 Networks Thunder ADC</strong>: These appliances provide high-speed L4–7 load balancing with a focus on application security and performance.</li><li><strong>Progress Kemp LoadMaster</strong>: A popular choice for businesses of all sizes due to its ease of use and flexible deployment options (hardware, virtual, and cloud).</li></ul><h4>Software and Open-Source</h4><p>These are software solutions that can be installed on standard servers. They provide flexibility and are often more cost-effective and scalable than hardware appliances.</p><ul><li><strong>HAProxy</strong>: While it has a popular open-source version, HAProxy Technologies offers a commercial enterprise-grade product with additional features and support, including the HAProxy ALOHA appliance.</li><li><strong>NGINX Plus</strong>: The commercial version of the widely-used NGINX web server and reverse proxy. It includes advanced L4 load balancing capabilities, health checks, and a powerful API.</li><li><strong>VMware NSX Advanced Load Balancer (formerly Avi)</strong>: A software-defined load balancer that provides centralized management and automation for applications running in any cloud.</li></ul><h4>Cloud-Native Services</h4><p>Major cloud providers offer managed L4 load balancing as a service, which is fully integrated into their platforms. These are ideal for applications hosted in the cloud.</p><ul><li><strong>AWS Network Load Balancer (NLB)</strong>: A fully managed L4 load balancing service designed for high performance and extremely low latency for TCP and UDP traffic.</li><li><strong>Google Cloud Network Load Balancer</strong>: A scalable, high-performance L4 service that can handle TCP, UDP, and other protocols, with options for regional or global distribution.</li><li><strong>Azure Load Balancer</strong>: Microsoft’s managed L4 load balancing service that distributes traffic across virtual machines or virtual machine scale sets in a specific region.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=879196ec7eb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Count Min Sketch]]></title>
            <link>https://medium.com/search-it/count-min-sketch-8943242250af?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8943242250af</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[real-time-streaming-data]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 05:10:52 GMT</pubDate>
            <atom:updated>2025-08-16T05:10:52.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LAzg4PCZyXU7cw8ZachtEg.png" /></figure><h3>Scenarios for Using Count-Min Sketch</h3><p>Count-Min Sketch is a clever data structure particularly useful for analyzing massive streams of data where it’s impossible to store everything. It’s a probabilistic approach, meaning it provides an estimate rather than a precise count, but it’s incredibly efficient. Here are some scenarios where it shines:</p><ul><li><strong>Traffic Monitoring:</strong> Imagine a network router handling billions of packets per second. You can’t store a log of every packet. A Count-Min Sketch can quickly estimate the number of times a particular IP address or port has been accessed, helping to identify potential DDoS attacks or network bottlenecks.</li><li><strong>Web Analytics:</strong> A website serving millions of users needs to track page views, clicks, and unique visitors in real-time. Instead of a massive database of every interaction, a Count-Min Sketch can provide a good approximation of how often a specific page is visited or an advertisement is clicked.</li><li><strong>Fraud Detection:</strong> In financial transactions, it’s essential to quickly identify unusual patterns. A Count-Min Sketch can be used to track the frequency of transactions from different accounts or credit cards, flagging those with unusually high or low activity for further investigation.</li></ul><h3>What is a Count-Min Sketch?</h3><p>At its core, a Count-Min Sketch is a data structure that helps you <strong>estimate the frequency of items in a large data stream</strong>. It’s a probabilistic data structure, which means it doesn’t give you the exact count, but rather a good approximation with a tunable margin of error. It works by trading a small probability of overcounting for significant memory savings.</p><p>It consists of a two-dimensional array, or a table, with <strong>d rows</strong> and <strong>w columns</strong>. Each row represents a different hash function.</p><p>Here’s how it works:</p><ol><li><strong>Initialization:</strong> The table is initialized with all zeros. The number of rows (d) and columns (w) are chosen based on the desired accuracy and confidence. A larger table provides a better estimate but uses more memory.</li><li><strong>Adding an Item:</strong> When a new item (e.g., an IP address, a URL, a user ID) arrives, it’s processed as follows:</li></ol><ul><li>For each of the d rows, a unique hash function is applied to the item.</li><li>The hash function for row i maps the item to a specific column j in that row (0≤j&lt;w).</li><li>The value at the intersection of row i and column j is incremented by 1.</li></ul><p>3. <strong>Querying an Item:</strong> To estimate the frequency of an item, you follow the same process:</p><ul><li>Apply each of the d hash functions to the item.</li><li>This gives you d different column indices, one for each row.</li><li>The estimated count is the <strong>minimum</strong> of the values in the cells at these d intersections. This is where the “min” in “Count-Min Sketch” comes from.</li></ul><p>Why take the minimum? Because of <strong>hash collisions</strong>. Multiple different items might hash to the same column in a given row. The value in that cell will be the sum of all the items that hashed to it. By taking the minimum across all rows, you are more likely to find a row where the value is closer to the true count of the item you’re interested in, as it’s less likely for the item to collide with other items across all different hash functions. The Count-Min Sketch will <strong>always overestimate or be exactly equal to the true count</strong>, never underestimate. The more rows you have, the more likely you are to get a good estimate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8943242250af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/count-min-sketch-8943242250af">Count Min Sketch</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RPC — Thrift or gRPC?]]></title>
            <link>https://medium.com/search-it/rpc-thrift-or-grpc-322185de9bfa?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/322185de9bfa</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 10:03:42 GMT</pubDate>
            <atom:updated>2025-08-12T10:03:42.820Z</atom:updated>
            <content:encoded><![CDATA[<h3>RPC — Thrift or gRPC?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwYVfxQLFL6F2iVSmAv-0w.png" /></figure><p>Thrift is a remote procedure call (RPC) framework that helps you build services that can communicate efficiently across different programming languages. Originally developed at Facebook, it is now an open-source project under the Apache Software Foundation.</p><p><strong>How Thrift Works</strong></p><p>Thrift is an RPC framework, which means it lets you call a function on a remote server as if it were a local function.<strong> </strong>It achieves this using a few key components:</p><ul><li><strong>Interface Definition Language (IDL)</strong>: You define your data structures and service interfaces in a language-neutral .thrift file. This file acts as a contract between the client and server. For example, you would define what data types a function accepts and what it returns.</li><li><strong>Thrift Compiler</strong>: The Thrift compiler takes your .thrift file and automatically generates the necessary client and server code in your chosen programming language (or languages). This generated code handles the boilerplate for serialization and network communication.</li><li><strong>Serialization and Transport</strong>: Thrift includes a stack of protocols and transports that define how the data is formatted and sent over the network. You can choose from various options, like a compact binary format for performance or JSON for human readability. The transport layer handles the underlying network connection (e.g., TCP sockets or HTTP).</li></ul><p>While REST is a flexible architectural style that uses standard HTTP methods to interact with resources, and HTTP is the underlying protocol for it, both Thrift and gRPC are more specialized for high-performance, cross-language communication. They are based on the RPC model, which focuses on invoking remote functions rather than manipulating resources.</p><p>Thrift supports a very broad range of programming languages, including some that gRPC may not. If your project involves a wide variety of services written in different or less common languages, Thrift might be a better fit. Thrift gives you a lot of control over the transport and serialization protocols. You can choose from various options, from a fast binary protocol for performance to a more readable JSON protocol. This flexibility can be useful for tailoring communication to specific environments. Thrift has been in use for a long time and is considered very stable. It’s well-suited for organizations with large, established systems and a need for a reliable, proven technology. On the other hand, gRPC is from the big daddy, Google.</p><p>Here is a simple comparison:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTwfz7SWV92-xM0E_lZ3LA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=322185de9bfa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/rpc-thrift-or-grpc-322185de9bfa">RPC — Thrift or gRPC?</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Base64 in System Design]]></title>
            <link>https://medium.com/search-it/base64-in-system-design-28085c4fcba1?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/28085c4fcba1</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[encoding]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 14:09:53 GMT</pubDate>
            <atom:updated>2025-08-11T14:17:36.866Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGLKxjvZIgdGE91uwtQhJQ.png" /></figure><p>Base64 encoding is a method of representing binary data in an ASCII string format. In system design, it’s used when you need to store or transmit binary data (like images, audio, or encrypted data) in systems that are designed to handle only text. Here’s where it’s most commonly used.</p><h3>Data Transfer</h3><p>When sending binary data over protocols that are text-based, such as HTTP or email (SMTP), Base64 encoding is essential.</p><ul><li><strong>Email Attachments:</strong> Email systems were originally designed for plain text. To send a file like a PDF or an image, the file’s binary data is Base64 encoded and then embedded within the email’s body. The recipient’s email client decodes it back into the original file.</li><li><strong>Data URIs:</strong> In web development, you can embed small images directly into a CSS file or HTML document using a <strong>Data URI</strong>. This avoids an extra HTTP request to fetch the image. The image’s binary data is Base64 encoded and included directly in the URL string, like data:image/png;base64,aNBORw1KGgk....</li><li><strong>JSON/XML Payloads:</strong> When a client-server API needs to send a binary file (e.g., a user’s profile picture upload) within a JSON or XML request body, the file is often Base64 encoded. This ensures the binary data doesn’t corrupt the text-based payload format.</li></ul><h3>Data Storage</h3><p>While storing large binary files on a file system is generally more efficient, Base64 encoding is useful for storing small binary data directly within a text-based database.</p><ul><li><strong>Small Images/Icons:</strong> A database might store small user profile pictures or application icons directly in a text field (e.g., VARCHAR or TEXT) as a Base64-encoded string. This is convenient for small files and avoids the need to manage a separate file system for these assets.</li><li><strong>Cookies:</strong> Cookies are text-based and have size limits. If you need to store a small amount of binary data, like an encrypted token, it must be Base64 encoded to be stored as a string in the cookie.</li></ul><h3>Security and Obfuscation</h3><p>Base64 isn’t an encryption method, but it’s often used in conjunction with security protocols.</p><ul><li><strong>Obfuscation:</strong> It can be used to obfuscate sensitive information in logs or URLs, making it unreadable to a casual observer.</li><li><strong>Authentication Tokens:</strong> In protocols like <strong>Basic Authentication</strong> (HTTP), the username and password are Base64 encoded before being sent in the Authorization header. This is a form of encoding, not encryption, so it should only be used over an encrypted connection (HTTPS).</li><li><strong>JWTs (JSON Web Tokens):</strong> A JWT is composed of a header, a payload, and a signature. Each of these parts is a Base64-encoded JSON string. This makes the token easy to transmit and process in text-based environments.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28085c4fcba1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/base64-in-system-design-28085c4fcba1">Base64 in System Design</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[High Volume Of Writes! What To Do?]]></title>
            <link>https://medium.com/search-it/high-volume-of-writes-what-to-do-30f52b411fd7?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/30f52b411fd7</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 11:18:02 GMT</pubDate>
            <atom:updated>2025-08-10T11:18:02.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uEOkyzXe6B8GDWtQBq8YjQ.png" /></figure><h3>The Problem Of High Volume Direct Writes To A DB</h3><p>High-volume direct writes to a database can lead to a number of critical issues, primarily due to the synchronous and resource-intensive nature of database operations.</p><ul><li><strong>Performance Bottlenecks:</strong> Each write operation requires system resources like CPU, memory, and most importantly, disk I/O. A large volume of individual writes can quickly saturate the I/O capacity of the database server. This leads to increased latency, long queues for writes, and a system that becomes unresponsive under load.</li><li><strong>Database Locks and Concurrency Issues:</strong> To ensure data integrity, databases use locks to prevent multiple operations from modifying the same data simultaneously. In a high-write scenario, many transactions may be waiting for locks to be released, leading to a state of contention. This severely degrades performance and can even cause deadlocks.</li><li><strong>Scalability Limitations:</strong> A traditional monolithic database is difficult to scale horizontally (by adding more servers). While you can scale vertically (by adding more powerful hardware), this is expensive and has a finite limit. Direct-write architecture doesn’t offer a built-in mechanism to distribute the write load across multiple servers.</li><li><strong>Lack of Resilience and Spikes:</strong> Without a buffer or a queue, the database becomes a single point of failure. If the database server goes down, all write operations fail. Moreover, a sudden spike in traffic can easily overwhelm the database, causing it to crash or become unavailable.</li></ul><h3>Examples Of High-Volume Write Situations</h3><p>I specialize in search engines. Web search engines face high-volume write situations, especially for crawling and indexing, writing log and analytics data, and real-time updates such as breaking news to maintain fresh information. Outside of search engines, here are some more commonly discussed scenarios where you will find high volume writes.</p><ul><li><strong>Uber Vehicle Location Updates:</strong> A Uber vehicle sending its location every 5 seconds generates a massive volume of small write operations. With millions of active vehicles, a direct-write model would quickly overwhelm a single database.</li><li><strong>IoT Sensor Data:</strong> A network of smart sensors (e.g., in a factory or smart city) continuously generating data about temperature, pressure, or air quality. Each sensor’s data point is a small write, but the aggregate volume from thousands or millions of sensors is immense.</li><li><strong>Social Media Feeds:</strong> Platforms like Twitter or Instagram handle millions of posts, likes, and comments every minute. Each of these user actions translates into a write operation.</li><li><strong>Financial Market Data:</strong> Stock exchanges and financial services need to process millions of transactions and real-time market data updates per second.</li></ul><h3>Tactics To Deal With This Situation</h3><ul><li><strong>Asynchronous Processing with Message Queues:</strong> Decouple the client’s request from the database write. The client sends data to a message queue, which returns an immediate acknowledgment. A separate background worker process then consumes messages from the queue and writes to the database. This acts as a buffer and smooths out traffic spikes.</li><li><strong>Batching Writes:</strong> Instead of performing a single write for each data point, collect multiple data points and perform a single, more efficient bulk write operation. This significantly reduces the overhead associated with each database transaction.</li><li><strong>Using In-Memory Databases or Caches:</strong> Write the high-volume, real-time data to a fast, in-memory store like Redis. Data can be persisted to a durable database periodically, or if it has a short lifespan, it can be left to expire.</li><li><strong>Sharding and Partitioning:</strong> Split the database into smaller, more manageable pieces (shards), each running on a separate server. This distributes the write load horizontally, allowing the system to scale its write capacity by simply adding more shards.</li><li><strong>Using a Write-Optimized Database:</strong> Choose a database specifically designed for high-write scenarios, often with an append-only log architecture and high horizontal scalability. NoSQL databases, particularly wide-column stores and time-series databases, are often a better fit than traditional relational databases for this purpose.</li></ul><h3>Tools And Products Designed To Address This Situation</h3><p><strong>Message Queues</strong></p><ul><li><strong>Apache Kafka:</strong> A highly scalable distributed streaming platform used for building real-time data pipelines and streaming applications. It’s excellent for high-throughput, fault-tolerant message passing.</li><li><strong>RabbitMQ:</strong> A general-purpose message broker that provides a robust messaging system for asynchronous processing.</li><li><strong>AWS SQS (Simple Queue Service):</strong> A managed message queuing service that simplifies the process of decoupling and scaling microservices.</li></ul><p><strong>In-Memory Databases/Caches</strong></p><ul><li><strong>Redis:</strong> An open-source, in-memory data store used as a database, cache, and message broker. It is renowned for its speed and versatility.</li><li><strong>Memcached:</strong> A high-performance, distributed memory caching system.</li></ul><p><strong>Write-Optimized Databases</strong></p><ul><li><strong>Apache Cassandra:</strong> A highly scalable, distributed NoSQL database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It is particularly known for its excellent write performance.</li><li><strong>InfluxDB:</strong> An open-source time-series database optimized for high-volume write and query scenarios involving time-stamped data, making it perfect for IoT and monitoring.</li><li><strong>ScyllaDB:</strong> A NoSQL database that is API-compatible with Cassandra but is built from the ground up for high-performance and low latency, often outperforming Cassandra.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30f52b411fd7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/high-volume-of-writes-what-to-do-30f52b411fd7">High Volume Of Writes! What To Do?</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutex Vs Semaphore]]></title>
            <link>https://medium.com/@vvtesh/mutex-vs-semaphore-af3377abfbe3?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/af3377abfbe3</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[threads]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sat, 09 Aug 2025 06:30:04 GMT</pubDate>
            <atom:updated>2025-08-09T06:30:04.986Z</atom:updated>
            <content:encoded><![CDATA[<p>Mutex and semaphores are both synchronization mechanisms used in concurrent programming to prevent race conditions and manage access to shared resources. The key difference lies in their purpose and how they are used.</p><h3>Mutex (Mutual Exclusion)</h3><p>A <strong>mutex</strong> is designed for mutual exclusion, ensuring that only one thread can access a critical section of code at a time. It acts like a lock on a single resource.</p><ul><li><strong>Purpose</strong>: Protect a shared resource from simultaneous access.</li><li><strong>Ownership</strong>: A mutex has an owner. The thread that locks the mutex must be the one to unlock it.</li><li><strong>Analogy</strong>: Think of a restroom with a single key. Only the person holding the key can enter. They must lock the door and then unlock it for the next person to use.</li></ul><h3>Semaphore</h3><p>A <strong>semaphore</strong> is a signaling mechanism that can control access to a pool of resources. It maintains a count of how many resources are available.</p><ul><li><strong>Purpose</strong>: Control access to a limited number of resources.</li><li><strong>Ownership</strong>: A semaphore does not have an owner. Any thread can signal (release) a semaphore, not just the one that acquired it.</li><li><strong>Types</strong>:</li><li><strong>Binary Semaphore</strong>: Functions similarly to a mutex but without ownership. It has a value of 0 or 1.</li><li><strong>Counting Semaphore</strong>: Has a value greater than 1, allowing a specific number of threads to access a resource simultaneously.</li><li><strong>Analogy</strong>: Imagine a parking garage with 100 spots. A sign at the entrance shows the number of available spots. Each time a car enters, the number decreases. When a car leaves, the number increases. The number on the sign is the semaphore. Any car can leave a spot, regardless of who parked it.</li></ul><p>In short, a mutex is for locking a single, shared resource, while a semaphore is for managing access to a limited number of resources</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af3377abfbe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP 1 or 2 or 3?]]></title>
            <link>https://medium.com/search-it/http-1-or-2-or-3-79605f538a66?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/79605f538a66</guid>
            <category><![CDATA[search-engines]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sat, 09 Aug 2025 04:23:47 GMT</pubDate>
            <atom:updated>2025-08-09T04:23:47.547Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIsDK4DMCiRNYmyEd4WRQQ.png" /><figcaption>To decide the right version, we think about these four qualities: simplicity, stability, speed and security.</figcaption></figure><p>The choice between HTTP/1.1 and HTTP/2 is crucial for a search system’s performance, as it directly impacts how quickly and efficiently a user receives search results. The main differences lie in how the protocols handle multiple requests and data transfer.</p><h3>HTTP/1.1’s Limitations</h3><p>In a search system using <strong>HTTP/1.1</strong>, each search request and its associated assets (CSS, JavaScript, images) require a separate TCP connection. This can lead to a few problems:</p><ul><li><strong>Head-of-Line Blocking</strong>: A slow-loading resource can block other resources from being requested on the same connection, delaying the rendering of the search results page.</li><li><strong>Increased Latency</strong>: Establishing a new TCP connection for each asset adds latency, especially when many small files are needed to display the search results page fully.</li></ul><h3>HTTP/2’s Advantages</h3><p><strong>HTTP/2</strong> addresses these issues with several key features that are beneficial for a search system:</p><ul><li><strong>Multiplexing</strong>: This is the most significant advantage. HTTP/2 allows a single TCP connection to handle multiple requests and responses simultaneously. For a search results page with many images and other assets, this means all resources can be downloaded concurrently, eliminating head-of-line blocking and speeding up the display of results.</li><li><strong>Header Compression</strong>: HTTP/2 compresses redundant request headers, reducing the amount of data transferred over the network. When a user performs multiple searches or navigates through result pages, this compression can save significant bandwidth.</li><li><strong>Server Push</strong>: The server can proactively “push” resources to the client that it knows the client will need, such as the CSS file or a common JavaScript library, without the client having to explicitly request them. This can dramatically improve the initial page load time for search results.</li></ul><h3><strong>HTTP/3</strong></h3><p>The latest major version, standardized in 2022, moves away from TCP and is built on the <strong>QUIC</strong> protocol, which runs over <strong>UDP</strong>.</p><ul><li><strong>Elimination of Head-of-Line Blocking</strong>: Unlike HTTP/2, a lost packet in one stream doesn’t block other streams, making it more robust on unreliable networks like mobile connections.</li><li><strong>Faster Handshake</strong>: The QUIC protocol combines the transport and cryptographic handshakes, significantly reducing connection establishment time.</li><li><strong>Improved Security</strong>: TLS encryption is built directly into QUIC and is a mandatory part of the protocol, making HTTP/3 inherently more secure.</li></ul><p>In short, using <strong>HTTP/2</strong> for a search system results in a <strong>faster, more responsive user experience</strong> due to its ability to handle multiple resources more efficiently over a single connection, making it the preferred choice for modern web applications. HTTP/3 gives stability on unreliable connection. Video and audio streaming services can maintain a smoother experience with fewer interruptions, even when a user’s connection quality fluctuates. Users switching between Wi-Fi and cellular networks can have their sessions persist without interruption, as HTTP/3 is designed for seamless connection migration.</p><p>Know that, many firewalls, load balancers, and network proxies are not configured to handle it correctly. This can cause traffic to be blocked or to fall back to HTTP/2, negating the benefits. The protocol’s built-in encryption and new framing make it more difficult for network administrators to inspect and troubleshoot traffic using traditional tools.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79605f538a66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/http-1-or-2-or-3-79605f538a66">HTTP 1 or 2 or 3?</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Role of FST in Autocomplete System]]></title>
            <link>https://medium.com/search-it/role-of-fst-in-autocomplete-system-071b704e42cd?source=rss-cc54ba238ec8------2</link>
            <guid isPermaLink="false">https://medium.com/p/071b704e42cd</guid>
            <category><![CDATA[search]]></category>
            <category><![CDATA[autocomplete]]></category>
            <category><![CDATA[search-engines]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Venkatesh Vinayakarao]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 15:03:03 GMT</pubDate>
            <atom:updated>2025-06-22T15:03:03.604Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnGbRLbMDLX6KoOy1545cw.png" /></figure><p>A Finite State Transducer (FST) is a data structure that can significantly enhance the design of an autocomplete system due to its efficiency and optimization for prefix-based lookups.</p><p>Here’s how FSTs help in designing an autocomplete system:</p><ul><li><strong>Memory-Optimized Graph Structure</strong>: An FST is a memory-based optimized graph structure. This optimization is crucial for systems that need to store a large volume of suggestions and retrieve them quickly.</li><li><strong>Efficient Prefix Lookups</strong>: FSTs are designed to facilitate efficient prefix lookups during user input. As a user types, the autocomplete system needs to quickly find all suggestions that start with the entered characters.</li><li><strong>Character-by-Character Navigation</strong>: When a completion suggestor uses an FST, it navigates the FST graph character by character as the user types. This allows the system to follow the path corresponding to the typed prefix within the FST.</li><li><strong>Suggestion Generation</strong>: Once the user finishes their input (or types a partial prefix), the completion suggestor examines the remaining endings in the FST to generate a list of suggestions. This enables the system to provide relevant completions dynamically.</li><li><strong>Common Implementation</strong>: Many autocomplete implementations, particularly those aiming for high performance, leverage a data structure called a <strong>weighted FST</strong>.</li><li><strong>Integration with Search Engines</strong>: FSTs are used as a building block for components like the “completion suggester” in Elasticsearch and the “Solr SuggestComponent” in Apache Solr. These components utilize FSTs to provide out-of-the-box autocomplete functionality, indexing predefined terms for fast suggestions.</li></ul><p>Here’s an example of how an FST (which operates similarly to a trie for prefix matching, as described in the sources) works in an autocomplete system:</p><p>1. Construction and Indexing:</p><ul><li>An FST is built from a list of potential suggestions, such as words or search terms like “Apple,” “Andy,” and “Arkansas”.</li><li>This data structure is an in-memory graph where each node represents a character, and paths through the nodes form complete words or prefixes. For example, a path might start with ‘A’, then branch to ‘P’ (for Apple), ’N’ (for Andy), or ‘R’ (for Arkansas).</li><li>Crucially, at every single node within the FST, the top terms for that prefix are cached. This pre-computation helps to optimize autocomplete efficiency and provide precise suggestion control.</li></ul><p>2. User Input and Character-by-Character Navigation:</p><ul><li>As a user begins typing, say, ‘A’, the autocomplete system navigates the FST graph character by character. It starts at the root of the FST and follows the edge to the node representing ‘A’.</li><li>If the user then types ‘P’, making the input “AP”, the system efficiently jumps in O(1) time from the ‘A’ node to the ‘P’ node. This direct jump is possible because each connection between characters is essentially a pointer within the FST’s graph structure.</li><li>The system continues this character-by-character traversal as the user types, following the path that corresponds to the entered prefix (e.g., “A” -&gt; “P” -&gt; “P” for “APP”).</li></ul><p>3. Suggestion Generation:</p><ul><li>Once the user has typed a prefix (or finishes their input), the completion suggestor examines the remaining endings in the FST that extend from the current node (the end of the typed prefix).</li><li>For instance, if the user has typed “APP”, the system immediately accesses the cached top suggestions for “APP” from that specific node, which might include “Apple” or “Application”.</li><li>This approach ensures fast read speeds because suggestions are pre-computed and directly accessible at each relevant node. The time to get suggestions for the next typed character is constant time (O(1)).</li></ul><p><strong>Summary</strong></p><p>FSTs are memory-optimized graph structures specifically designed for efficient prefix lookups in autocomplete systems. They enable fast, constant-time (O(1)) suggestion retrieval by navigating the graph character by character and caching popular terms at each node. This approach optimizes autocomplete efficiency and provides precise suggestion control, commonly used in search components like Elasticsearch’s completion suggester.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=071b704e42cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/search-it/role-of-fst-in-autocomplete-system-071b704e42cd">Role of FST in Autocomplete System</a> was originally published in <a href="https://medium.com/search-it">Search It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>