<?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 Swaroop Rath on Medium]]></title>
        <description><![CDATA[Stories by Swaroop Rath on Medium]]></description>
        <link>https://medium.com/@swaroopr?source=rss-6e6ee3a4e9f2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BOILFig2fHV3ez8m.jpg</url>
            <title>Stories by Swaroop Rath on Medium</title>
            <link>https://medium.com/@swaroopr?source=rss-6e6ee3a4e9f2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:51:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swaroopr/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[Back-of-the-envelope estimates]]></title>
            <link>https://medium.com/@swaroopr/back-of-the-envelope-estimates-c31b52eff23a?source=rss-6e6ee3a4e9f2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c31b52eff23a</guid>
            <dc:creator><![CDATA[Swaroop Rath]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 01:25:40 GMT</pubDate>
            <atom:updated>2024-07-11T15:02:42.024Z</atom:updated>
            <content:encoded><![CDATA[<p>Number for Back-of-the-envelope estimates</p><h3>Power of two</h3><p>Although data volume can become enormous when dealing with distributed systems, calculation all boils down to the basics. To obtain correct calculations, it is critical to know the data volume unit using the power of 2. A byte is a sequence of 8 bits. An ASCII character uses one byte of memory (8 bits). Below is a table explaining the data volume unit (Table 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*qBniWSzBtvX76F9R4aRnmA.png" /></figure><h3>Latency numbers every programmer should know</h3><p>Dr. Dean from Google reveals the length of typical computer operations in 2010.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UN14WOoSrlurB8DtAQwhow.png" /></figure><p>ns = nanosecond, µs = microsecond, ms = millisecond</p><p>1 ns = 10^-9 seconds</p><p>1 µs= 10^-6 seconds = 1,000 ns</p><p>1 ms = 10^-3 seconds = 1,000 µs = 1,000,000 ns</p><p>A Google software engineer built a tool to visualize Dr. Dean’s numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GM5yO5qJ4glkU6-d9-xSqw.png" /></figure><p>By analyzing the numbers in Figure 1, we get the following conclusions:</p><ul><li>Memory is fast but the disk is slow.</li><li>Avoid disk seeks if possible.</li><li>Simple compression algorithms are fast.</li><li>Compress data before sending it over the internet if possible.</li><li>Data centers are usually in different regions, and it takes time to send data between them.</li></ul><h3>Availability numbers</h3><p>High availability is the ability of a system to be continuously operational for a desirable long period of time. It is measured as a percentage, with 100% meaning a service with 0 downtime. Most services fall between 99% and 100%.</p><p>A service level agreement (SLA) is a commonly used term for service providers. This is an agreement between you (the service provider) and your customer, and this agreement formally defines the level of uptime your service will deliver. Cloud providers Amazon [4], Google [5] and Microsoft [6] set their SLAs at 99.9% or above. Uptime is traditionally measured in nines. The more the nines, the better. As shown in Table 3, the number of nines correlate to the expected system downtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GM5yO5qJ4glkU6-d9-xSqw.png" /></figure><h3>Back-of-the-envelope estimates for Managed Service</h3><p>Back-of-the-envelope estimates can still be quite useful even if you’re opting for a fully managed service. Here are a few reasons why:</p><p>1. <strong>Budgeting</strong>: These estimates can help you get a rough idea of the costs involved, which is essential for budgeting and financial planning.</p><p>2. <strong>Feasibility</strong>: They can give you a quick sense of whether a particular solution is viable within your constraints, whether financial, technical, or temporal.</p><p>3. <strong>Comparison</strong>: They allow you to compare different managed services or configurations at a high level, helping to narrow down your options before diving into detailed analyses.</p><p>4. <strong>Communication</strong>: Quick estimates can facilitate discussions with stakeholders, providing a ballpark figure that can be refined later.</p><p>5. <strong>Decision Making</strong>: They support early decision-making processes by providing a preliminary assessment of the resources required.</p><p>While detailed estimates and analyses are necessary for final decisions, back-of-the-envelope calculations are a valuable tool for initial planning and evaluation. Must know numbers for back-of-the-envelope estimates</p><p>For back-of-the-envelope estimates, there are several key numbers and metrics you should be familiar with to make quick and reasonably accurate calculations. These typically depend on the context of what you’re estimating, but here are some general must-know numbers:</p><p><strong>General Business and Financial Estimates</strong></p><p>1. <strong>Revenue and Costs</strong>:</p><p>• Average revenue per user (ARPU)</p><p>• Customer acquisition cost (CAC)</p><p>• Lifetime value (LTV) of a customer</p><p>• Operating expenses (OPEX)</p><p>• Capital expenditures (CAPEX)</p><p>2. <strong>Market and Sales</strong>:</p><p>• Total addressable market (TAM)</p><p>• Market penetration rates</p><p>• Sales conversion rates</p><p><strong>Technical and Infrastructure Estimates</strong></p><p>1. <strong>Cloud Services</strong>:</p><p>• Cost per compute unit (e.g., per vCPU hour)</p><p>• Cost per GB of storage</p><p>• Data transfer costs (e.g., per GB in/out)</p><p>• Cost per request (for serverless functions)</p><p>• Monthly uptime percentage/service level agreements (SLAs)</p><p>2. <strong>Networking</strong>:</p><p>• Bandwidth costs (per Mbps or per GB transferred)</p><p>• Latency metrics (e.g., average latency in ms)</p><p>3. <strong>Database Services</strong>:</p><p>• Cost per GB of database storage</p><p>• Cost per query/transaction</p><p>4. <strong>Application Services</strong>:</p><p>• Cost per API call</p><p>• Cost per user session</p><p><strong>Operational Metrics</strong></p><p>1. <strong>Performance</strong>:</p><p>• Transactions per second (TPS)</p><p>• Requests per second (RPS)</p><p>• Average response time</p><p>2. <strong>Scalability</strong>:</p><p>• Peak load handling capacity</p><p>• Horizontal vs. vertical scaling costs</p><p><strong>Team and Productivity Estimates</strong></p><p>1. <strong>Engineering</strong>:</p><p>• Average developer salary</p><p>• Time to hire</p><p>• Average project duration</p><p>2. <strong>Productivity</strong>:</p><p>• Developer productivity (e.g., lines of code per day, features delivered per sprint)</p><p>• Burn rate (e.g., monthly spend on salaries and overhead)</p><p><strong>Example Scenarios</strong></p><p>• <strong>Cloud Hosting</strong>: To estimate the cost of hosting a web application on AWS:</p><p>• Number of servers needed (based on traffic estimates)</p><p>• Storage requirements</p><p>• Data transfer estimates</p><p>• Compute hours</p><p>• Additional services (e.g., database, CDN)</p><p>• <strong>SaaS Business</strong>: To estimate potential revenue:</p><p>• Expected number of users</p><p>• Pricing model (e.g., subscription fees)</p><p>• Conversion rates from free trials to paid users</p><p>By having these numbers at your fingertips, you can quickly piece together rough estimates to guide your decision-making and planning processes.</p><p>Check out this chat for more details: <a href="https://chatgpt.com/share/e5019b52-deaf-4df4-b5de-3d1ff979f22b">https://chatgpt.com/share/e5019b52-deaf-4df4-b5de-3d1ff979f22b</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c31b52eff23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Per Server]]></title>
            <link>https://medium.com/@swaroopr/per-server-b79859c4f0fb?source=rss-6e6ee3a4e9f2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b79859c4f0fb</guid>
            <dc:creator><![CDATA[Swaroop Rath]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 01:02:14 GMT</pubDate>
            <atom:updated>2024-07-11T01:05:40.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>API Connections per server</h3><p>The number of API connections a typical web server can support depends on factors similar to those for WebSocket connections. Here are the key factors:</p><p>1. **Server Hardware**: CPU, memory, and network capacity are critical.<br>2. **Server Software and Configuration**: Different web servers and their configurations (e.g., Apache, Nginx, Node.js) have varying capacities.<br>3. **Connection Type**: Persistent connections (like those for WebSockets) versus short-lived HTTP requests impact capacity differently.<br>4. **Workload**: The complexity of processing each API request (e.g., database access, computation) affects the number of connections.<br>5. **Resource Limits**: Operating system limits, such as the maximum number of file descriptors.</p><p>### Typical Numbers<br>- **Low-end Servers**: A basic server might handle several hundred to a few thousand API requests per second.<br>- **Optimized Setups**: With optimizations, servers can handle tens of thousands of requests per second.<br>- **High-end Systems**: Large-scale systems with load balancing and distributed architectures can handle millions of requests per second.</p><p>### Example<br>- **Nginx**: Can handle tens of thousands of requests per second with proper tuning.<br>- **Node.js**: Known for handling a large number of concurrent connections efficiently, potentially supporting tens of thousands of requests per second on modern hardware.<br>- **Apache**: Can handle a high number of requests, but might require more resources compared to event-driven servers like Nginx or Node.js.</p><p>### Considerations for Scaling API Connections<br>- **Load Balancing**: Distribute requests across multiple servers to increase capacity.<br>- **Caching**: Use caching strategies (e.g., CDNs, in-memory caches) to reduce load on the server.<br>- **Database Optimization**: Efficient database access and query optimization can significantly improve the server’s capacity.<br>- **Asynchronous Processing**: Non-blocking I/O and asynchronous processing can enhance performance.</p><p>### Example Calculation<br>Assuming a Node.js server:<br>- Each request takes 50ms to process.<br>- The server can handle 20 requests per second per core.<br>- With an 8-core server, this results in 160 requests per second.</p><p>For highly optimized systems:<br>- If each request takes 10ms, the server can handle 100 requests per second per core.<br>- An 8-core server can handle 800 requests per second.</p><p>By leveraging load balancing and multiple servers, you can scale horizontally to handle much higher loads.</p><p>In summary, while a typical web server can handle several hundred to a few thousand API connections per second, with proper optimization and scaling strategies, the number can be significantly higher.</p><h3>Number of web-socket connections</h3><p>The number of WebSocket connections a typical web server can support depends on several factors, including the server’s hardware specifications, network bandwidth, and the software stack being used. Here are some general considerations:</p><p>1. **Hardware Specifications**: More CPU, memory, and network bandwidth can support more connections.<br>2. **Server Software and Configuration**: Web servers like Nginx, Apache, or dedicated WebSocket servers like `socket.io` (on Node.js) have different capabilities and optimizations.<br>3. **Connection Handling**: How the server handles connections (e.g., event-driven vs. thread-based) affects scalability. Event-driven architectures (like those in Node.js or Nginx) are generally more scalable for WebSockets.<br>4. **Resource Limits**: OS-level limits on the number of file descriptors or network sockets can also impact the maximum number of connections.</p><p>### Typical Numbers<br>- **Low-end Servers**: A basic server might handle a few thousand concurrent WebSocket connections.<br>- **Optimized Setups**: With proper optimization and robust hardware, servers can handle tens of thousands of connections.<br>- **High-end Systems**: Large-scale deployments, with distributed architecture and load balancing, can support hundreds of thousands to millions of WebSocket connections.</p><p>### Example<br>A well-optimized Node.js server can handle upwards of 50,000 to 100,000 concurrent WebSocket connections on modern hardware. This assumes a relatively low message frequency and lightweight processing per message.</p><p>### Considerations for Scaling<br>- **Load Balancing**: Distributing connections across multiple servers.<br>- **Horizontal Scaling**: Adding more servers to handle more connections.<br>- **Resource Monitoring**: Continuously monitoring and optimizing resource usage.</p><p>In summary, while a typical web server might support several thousand WebSocket connections, with proper tuning and scaling strategies, the number can be significantly higher.</p><h3>DB Connections per DB Server</h3><p>The number of database connections a typical database server can support depends on various factors, including the server’s hardware, database software, and configuration. Here are the key factors and their impact:</p><p><strong>Key Factors</strong></p><p>1. <strong>Hardware Specifications</strong>: CPU, memory, and disk I/O capacity are crucial.</p><p>2. <strong>Database Software and Configuration</strong>: Different RDBMS (e.g., MySQL, PostgreSQL, SQL Server) have varying capabilities and configurations.</p><p>3. <strong>Connection Handling</strong>: How the database manages connections (e.g., connection pooling) affects scalability.</p><p>4. <strong>Query Complexity</strong>: The complexity and efficiency of SQL queries impact performance.</p><p>5. <strong>Read vs. Write Requests</strong>: Read operations are generally less resource-intensive compared to write operations.</p><p><strong>Typical Numbers</strong></p><p>• <strong>Low-end Servers</strong>: Might handle a few hundred to a thousand connections.</p><p>• <strong>Optimized Setups</strong>: Can handle several thousand connections with proper tuning.</p><p>• <strong>High-end Systems</strong>: With load balancing and optimized configurations, can handle tens of thousands of connections.</p><p><strong>Impact of Read and Write Requests</strong></p><p>• <strong>Read Requests</strong>: Generally less resource-intensive. More read requests can be handled concurrently, especially with effective caching.</p><p>• <strong>Write Requests</strong>: More resource-intensive due to the need for data integrity and consistency checks, transaction management, and disk I/O.</p><p><strong>Example</strong></p><p>Assume a relational database (e.g., MySQL) with an employee details table.</p><p><strong>Read Requests</strong></p><p>• <strong>Cached Reads</strong>: If data is cached, read requests are fast and less resource-intensive.</p><p>• <strong>Non-cached Reads</strong>: Involves disk I/O, but still generally faster than writes.</p><p><strong>Write Requests</strong></p><p>• <strong>Single Writes</strong>: Each write operation involves disk I/O, locking mechanisms, and possibly replication in a distributed setup.</p><p>• <strong>Batch Writes</strong>: Grouping write operations can be more efficient but still more resource-intensive than reads.</p><p><strong>Performance Estimation</strong></p><p>• <strong>Reads</strong>: A modern server might handle tens of thousands of read requests per second.</p><p>• <strong>Writes</strong>: A modern server might handle a few thousand write requests per second.</p><p><strong>Connection Management</strong></p><p>• <strong>Connection Pooling</strong>: Using a connection pool can significantly improve performance by reusing connections rather than creating new ones for each request.</p><p>• <strong>Query Optimization</strong>: Efficient queries reduce the load on the database server.</p><p><strong>Example Calculation</strong></p><p>Assume a MySQL server:</p><p>• <strong>Hardware</strong>: 8-core CPU, 32GB RAM, SSD storage.</p><p>• <strong>Reads</strong>: Can handle 30,000 read requests per second.</p><p>• <strong>Writes</strong>: Can handle 3,000 write requests per second.</p><p>If the workload is 70% reads and 30% writes:</p><p>• <strong>Total Requests</strong>: 21,000 reads + 900 writes per second.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b79859c4f0fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NQueen Succint solution]]></title>
            <link>https://medium.com/@swaroopr/nqueen-succint-solutions-fa53bd7d98ef?source=rss-6e6ee3a4e9f2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa53bd7d98ef</guid>
            <dc:creator><![CDATA[Swaroop Rath]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 18:09:39 GMT</pubDate>
            <atom:updated>2023-04-02T03:02:05.993Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Y-f0sxom6Yh4Cd1FJrTYnQ.jpeg" /></figure><p><a href="https://leetcode.com/problems/n-queens/">Leetcode 51. N-Queens.</a><br><a href="https://www.geeksforgeeks.org/printing-solutions-n-queen-problem/">Geeks for Geeks N Queen</a></p><p><strong>Problem Description</strong></p><blockquote>The <strong>n-queens</strong> puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.</blockquote><blockquote>Given an integer n, return <em>all distinct solutions to the </em><strong><em>n-queens puzzle</em></strong>. You may return the answer in <strong>any order</strong>.</blockquote><blockquote>Each solution contains a distinct board configuration of the n-queens’ placement, where &#39;Q&#39; and &#39;.&#39; both indicate a queen and an empty space, respectively.</blockquote><p>My Java and python solutions for the <a href="https://leetcode.com/problems/n-queens/">N-Queens</a> problem are below. It is more succint and easy to understand than the ones on LeetCode and Geeks For Geeks. The python version is less than 25 lines and should be easy to code in an interview. The Java version is a little more verbose (&lt; 50 lines).</p><p>If you have insights into how to make the code more simple, readable, and succinct, please share them in the comments. Code review comments on the GitHub Gist are welcome. I feel the code below leans a bit more toward being succint than readable. It should be readable to experienced Python and Java developers.</p><h3>Python solution</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c17a0a1c7c1561f1602015b98f584c1/href">https://medium.com/media/1c17a0a1c7c1561f1602015b98f584c1/href</a></iframe><h3>Java Solution</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0db6c93fa60eb75fc70d752b972fdd22/href">https://medium.com/media/0db6c93fa60eb75fc70d752b972fdd22/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*izONHpOIzRpKBbfHirwv9w.png" /><figcaption>1/92 solution to 8 queen problem</figcaption></figure><h3>Explanation</h3><ol><li>A 1-D list of integers represents the board state. An ith entry on this array will be less than N and represents the position of the queen on the ith column. Please check out the above diagram, “1/92 solution to 8 queen problem,” for an example.</li><li>We use recursion to generate all possible board combinations. Loops can be used when N is specified — for example, 8 queen problem. In this example, n is variable, and recursion to generate all possible board combinations with backtracking leads to a much simpler solution.</li><li>The “is_attack” function checks that the nth queen is not attacked by queens in 0 to n-1 positions. As we place a new queen on the nth column, we need to check that none of the queens placed before are attacking the new queen. We do not need to check for every possible pair of queens; checking only for the new queen placed on the nth column is sufficient. We check that the new queen is not on the same row and not on a diagonal. It’s obviously in a new column. The row check is straightforward. The diagonal check involves comparing the difference in absolute values of row numbers with the difference in column numbers.</li><li>The to_string method converts the internal 1D list representation to a list of string representations that leetcode wants in the output. The list of string representations is easier to visualize. Python string operators and list comprehensions enable us to do this in a single line. Java 11’s string repeat function and StringBuilder are used to build the string representation in Java.</li></ol><h3>Comparative analysis</h3><p>This is simpler and succint compared to <a href="https://www.geeksforgeeks.org/printing-solutions-n-queen-problem/">Geeks for Geeks</a> and <a href="https://leetcode.com/problems/n-queens/editorial/">Leetcode versions</a>.</p><h3>Enhancements</h3><p>The tree generated and traversed by the algorithm is exponential and the algorithm will timeout pretty quickly as n increases above 10. The tree traversed can be reduced because every solution has a mirror image solution along the middle row. Check out the images below as an example. The code snippet below uses this to traverse only half of the sub-tree the code above traverses. The original solution might time out for n≥12 on many online platforms, while the code below would work for a few additional values of n.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*iiXF7Vksc38OsRNkQ31zSw.png" /><figcaption>Mirror solutions for the 4-Queen problem!</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a83c956b2c149a82c737b22e2bb0f09b/href">https://medium.com/media/a83c956b2c149a82c737b22e2bb0f09b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa53bd7d98ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>