<?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 Ashok Tankala on Medium]]></title>
        <description><![CDATA[Stories by Ashok Tankala on Medium]]></description>
        <link>https://medium.com/@ashok.tankala?source=rss-555eb7b60303------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PrrYCgMDaoaCekxhMAbZgA.jpeg</url>
            <title>Stories by Ashok Tankala on Medium</title>
            <link>https://medium.com/@ashok.tankala?source=rss-555eb7b60303------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:21:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashok.tankala/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[Understanding Latency & Key Strategies to Optimise Application Performance]]></title>
            <link>https://medium.com/@ashok.tankala/understanding-latency-key-strategies-to-optimise-application-performance-4b41efa4af00?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b41efa4af00</guid>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[tech-tips]]></category>
            <category><![CDATA[latency-reduction]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[web-performance]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Fri, 27 Sep 2024 06:42:03 GMT</pubDate>
            <atom:updated>2024-09-27T06:42:03.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4Pl16rGBG7bSP3X3.png" /></figure><p>In my previous post <a href="https://lulaguide.substack.com/p/performance-monitoring-101-what-to"><strong>Performance Monitoring 101</strong></a> to improve performance, we need to minimise Latency between Request &amp; Response and maximise Throughput with Concurrency. In this post, we will concentrate on some of the main types of latencies and how to tackle them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*PVSzO_y_7sXTB-bS.png" /><figcaption>Figure 1: A simple application architecture</figcaption></figure><p>We will take this as our application architecture for reference purposes.</p><h4>Network Latency</h4><p>In a typical application setup (Figure 1), there are usually two types of networks involved: Internet and Intranet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*1eyV_WegeQvYCZJD.png" /></figure><p><strong>- Internet</strong>: Interactions between the client and the load balancer, the application server and any external systems typically occur over the Internet.</p><p><strong>- Intranet</strong>: Interactions between internal components like the load balancer, web server and application server happen over the Intranet.</p><p>Internet connections involve multiple hops, leading to higher latency, unreliability, and slower performance compared to intranet connections.</p><p>To establish a TCP connection over the internet, the client initiates a connection that the server acknowledges, requiring one round trip. However, when using HTTPS (SSL), three round trips are needed-one for the TCP connection and two for SSL key exchange. After these round trips, data can be exchanged between the client and server, totalling four round trips for the initial connection.</p><p>The more connections established with the server, the greater the perceived slowness.</p><h4>Strategies to Reduce Network Latency</h4><p><strong>1. Position Servers Closer to Clients: </strong>Position your servers near your primary customer base. For instance, if most customers are in India, hosting servers in India reduces the number of network hops, lowering latency.</p><p><strong>2. Content Delivery Networks (CDNs):</strong> CDNs use geographically distributed servers to bring content closer to users, reducing the physical distance data needs to travel.</p><p><strong>3. Connection Pools:</strong> Reuse existing connections wherever possible, including intranet connections, to avoid the overhead of repeatedly creating new connections.</p><p><strong>4. Upgrade to HTTP/2 or HTTP/3:</strong> Use modern versions of HTTP, such as HTTP/2 or HTTP/3, which support multiplexing and reduce latency compared to older versions like HTTP/1.1.</p><p><strong>5. Cache Data:</strong> Avoid transferring data between clients and servers when possible. Cache static data, session data, and database query results to save time.</p><p><strong>6. Data Compression:</strong> Compress data before transmission (e.g., using gzip) to reduce the amount of data sent over the network. Minify JavaScript, CSS, and HTML files to decrease their size.</p><p><strong>7. Use Efficient Data Formats:</strong> For communication between microservices, consider RPC calls for efficient data transfer. For images, use formats like WebP, which offer better compression, if supported by the client’s browser.</p><p>These strategies can significantly reduce network latency, improving the responsiveness of your application.</p><h4>Memory Latency</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kdbmlA5kBhQJwfIa.jpeg" /><figcaption>Source: <a href="https://simple.wikipedia.org/wiki/Computer_memory">https://simple.wikipedia.org/wiki/Computer_memory</a></figcaption></figure><p>Accessing data from RAM is generally quick, especially with modern RAM like DDR4 or DDR5. However, latency issues can still arise due to factors such as:</p><ol><li><strong>Improper Memory Allocation:</strong> Allocating insufficient sizes for heap memory or database buffer memory can lead to performance bottlenecks.</li><li><strong>Exceeding RAM Capacity:</strong> When memory usage exceeds the available RAM, two major problems can occur:<br><strong>2.1 Swap Memory Usage:</strong> Excess data spills over to swap memory on the hard disk, which is much slower than RAM.<br><strong>2.2 Aggressive Garbage Collection:</strong> To free up memory, the system may frequently trigger garbage collection, slowing down the application and causing performance issues.</li></ol><h4>Strategies to Reduce Memory Latency</h4><ol><li><strong>Optimize Memory Usage<br>a. Avoid Unnecessary Object Creation:</strong> Minimize the creation of objects, especially in loops and reuse objects when possible using techniques like object pooling.<br><strong>b. Choose Efficient Data Structures:</strong> Use the most memory-efficient data structures; for example, prefer <em>ArrayList</em> over <em>LinkedList</em> for random access.<br><strong>c. Clean-Up Code:</strong> Remove unused code and variables, as even the codebase consumes memory.</li><li><strong>Detect and Fix Memory Leaks<br>a. Identify Memory Leaks:</strong> Use profilers to detect memory leaks caused by objects that are not properly dereferenced, especially in growing collections.<br><strong>b. Manage Shared Objects:</strong> Monitor shared objects, as they can grow unexpectedly due to multi-threaded access. Avoid creating shared objects whenever possible.</li><li><strong>Implement Efficient Caching Strategies<br>a. Use Size-Limited Caches:</strong> Implement caches with size limits and eviction policies like LRU (Least Recently Used) to prevent unbounded memory growth.<br><strong>b. Offload Large Caches:</strong> For large caches, consider using external solutions like Redis or Memcached to reduce heap memory usage.</li><li><strong>Tune Garbage Collection<br>a. Adjust GC Parameters:</strong> Tune garbage collector parameters and select the appropriate garbage collector based on your application’s needs.<br><strong>b. Choose the Right Garbage Collector:</strong> Use collectors that minimize pause times for real-time applications and batch-processing collectors for batch jobs where pauses are acceptable.</li><li><strong>Review Third-Party Libraries<br>a. Select Memory-Efficient Libraries:</strong> Choose third-party libraries carefully, focusing on those known for efficient memory usage, especially when handling large datasets.<br><strong>b. Keep Libraries Updated:</strong> Ensure that libraries are updated to leverage any performance improvements or memory optimizations.</li><li><strong>Database Memory Optimizations<br>a. Properly Configure Buffer Memory:</strong> Ensure that the database buffer memory is configured correctly to optimize performance.<br><strong>b. Normalize or Denormalize Data:</strong> Choose data normalization or denormalization based on your specific needs; normalization is generally preferred, but denormalization can be advantageous in certain scenarios.</li></ol><h4>Disk Latency</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4036Sv1C2ErklIXq.jpeg" /><figcaption>Source: <a href="https://nzxt.com/news/what-s-the-difference-between-an-ssd-hard-drive">https://nzxt.com/news/what-s-the-difference-between-an-ssd-hard-drive</a></figcaption></figure><p>Disk I/O is one of the slowest types of I/O operations, yet it’s crucial for many tasks, including database operations (select, insert, update, etc.) and accessing static files like images. While disk latency can be a significant bottleneck, sequential writes, such as logging, tend to be faster. For performance-critical applications, asynchronous logging is recommended.</p><h4>Strategies to Reduce Disk Latency</h4><ol><li><strong>Use Caching Mechanisms<br>a. Application-Level Caching:</strong> Implement in-memory caching solutions like Redis or Memcached to minimize direct disk access and speed up data retrieval.<br><strong>b. Web Content Caching:</strong> Use reverse proxies like Nginx to cache static content such as images, HTML, and CSS, reducing the need to fetch these files from disk repeatedly.</li><li><strong>Use Faster Disk I/O Options<br>a. Upgrade to SSDs:</strong> If you haven’t already, switch to SSDs, which provide significantly faster read and write speeds compared to traditional HDDs. Choose the SSD type that best fits your needs, as cloud providers offer various performance tiers.</li><li><strong>Database Optimization<br>a. Data Normalization:</strong> Properly normalize data to avoid loading large, repetitive datasets from disk, which can slow down performance.<br><strong>b. Index Management:</strong> Create indexes where necessary to speed up data retrieval, but avoid excessive indexing as it can degrade write performance.<br><strong>c. Query Optimization:</strong> Optimize database queries by selecting only the required data and avoiding unnecessary data access, which reduces I/O load.</li></ol><h4>CPU Latency</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*aVRVBC2OQawypw3S.jpeg" /><figcaption>source: <a href="https://www.trustedreviews.com/explainer/what-is-a-cpu-2950255">https://www.trustedreviews.com/explainer/what-is-a-cpu-2950255</a></figcaption></figure><p>The CPU is the core component that drives overall system performance, making it crucial to minimize latency for optimal efficiency. Usually it happens mostly due to our inefficient coding &amp; context switching.</p><h4>Strategies to Reduce CPU Latency</h4><ol><li><strong>Efficient Algorithms &amp; Data Structures<br></strong>a. Latency often arises from using inefficient algorithms or data structures, and selecting the right ones for specific tasks can greatly improve performance. This challenge is closely tied to developers’ choices, so there isn’t a one-size-fits-all solution. It’s essential to find the right tools for the job rather than relying solely on familiar methods.</li><li><strong>Batching Operations<br></strong>a. Batching operations like I/O and database queries can save CPU time by reducing the frequency of context switching and minimizing the overhead of connection creation (e.g., HTTP or database connections). This improves processing speed by handling multiple tasks in a single operation.</li><li><strong>Optimize Multithreading and Concurrency<br></strong>a. Use lock-free or low-lock algorithms to reduce contention between threads, enhancing CPU core utilization and reducing latency.<br>b. Manage thread overhead with thread pools to minimize context switching. Set the thread pool size to match or slightly under the number of available CPU cores to optimize resource usage. But it totally depends if tasks are not CPU intensive tasks then the thread pool size could be a different number.</li></ol><h4>Latency Numbers Every Programmer Should Know</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/979bc7aa97be68c9ed65b3f10c8be383/href">https://medium.com/media/979bc7aa97be68c9ed65b3f10c8be383/href</a></iframe><p><a href="https://static.googleusercontent.com/media/sre.google/en//static/pdf/rule-of-thumb-latency-numbers-letter.pdf">https://static.googleusercontent.com/media/sre.google/en//static/pdf/rule-of-thumb-latency-numbers-letter.pdf</a></p><p>The two references above are widely used to quantify latency numbers that we might encounter under various scenarios. While they may not reflect the latest data, they provide a useful relative comparison to understand potential performance impacts.</p><blockquote><em>FYI: n — nano, µ — micro, m — milli</em></blockquote><p><strong>CPU level (1 ns — 10 ns): </strong>L1 &amp; L2 caches are integrated into the microprocessor chip itself so if we are playing with the data at this level things happen below 10ns speed.</p><p><strong>RAM level (100 ns): </strong>Accessing data from RAM takes about 100 ns. Since Redis is an in-memory data store, reading data from it typically takes around 100 ns.</p><p><strong>Data Compression (2 µs — 3 µs): </strong>Data compression is much faster that’s why it is always better to compress the data and transmit it.</p><p><strong>Intranet level (500 µs or 0.5 ms): </strong>If we need some data from a separate Redis server which is present in the same data centre then requesting and getting that back to our server takes less than a millisecond.</p><p><strong>SSD level (1 ms): </strong>Reading 1 MB of data from a hard disk(SSD) or Inserting data in the Database including storing the data, updating indexes, and flushing logs, often takes about 1 ms.</p><p><strong>Internet level (150 ms): </strong>A third-party API call such as from one continent to the other continent and back, can experience a latency of around 100 ms.</p><p>These numbers provide a clear understanding of expected latencies when designing application architecture. With this reference, we can make more informed decisions and anticipate potential performance impacts accurately.</p><p><em>Originally published at </em><a href="https://lulaguide.substack.com/p/understanding-latency-and-key-strategies">https://lulaguide.substack.com/p/understanding-latency-and-key-strategies</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b41efa4af00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running a half marathon in Ladakh showed me how the people you spend time with shape your life]]></title>
            <link>https://medium.com/@ashok.tankala/running-a-half-marathon-in-ladakh-showed-me-how-the-people-you-spend-time-with-shape-your-life-10e6d67f9644?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/10e6d67f9644</guid>
            <category><![CDATA[self-betterment]]></category>
            <category><![CDATA[power-of-influencers]]></category>
            <category><![CDATA[ladakh-marathon]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[growth-mindset]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Wed, 11 Sep 2024 10:45:35 GMT</pubDate>
            <atom:updated>2024-09-11T10:45:35.810Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FOmVCLLvcRgGd-Ju.jpeg" /></figure><p>Last week, I had an amazing experience of running a half marathon in Leh, Ladakh with my friends (Venu, Nil, Prakash). As I reflect on that journey and came across this photo, I was reminded of a powerful quote by Jim Rohn:</p><blockquote>“We are the average of the five people we spend the most time with.” — Jim Rohn</blockquote><p>Leh is a destination known for its stunning landscapes and is often seen as a biker’s paradise. People from all over the world come there to conquer its challenging roads on motorcycles. But I found myself there for an entirely different reason-to run.</p><p>I’ve never considered myself much of a biker. In fact, Leh wasn’t even on my list of places to visit. But everything changed when I started running and surrounded myself with fellow runners. Their passion and drive began to influence my perspective and suddenly, Leh transformed from a biker’s dream to a running challenge I couldn’t resist.</p><p>If I hadn’t spent time with runners, I might have always seen Leh through the lens of a motorcyclist, never realizing its potential as a runner’s haven. For us, Leh is more than just a scenic backdrop; it’s a place that tests our endurance with its tough terrain, high altitude and unforgivable weather. It’s a place where we push our limits and find joy in the struggle.</p><p>This experience taught me an important lesson: every place, word and experience in life can take on a different meaning depending on the people you surround yourself with. The company you keep shapes your perceptions and ultimately, your reality.</p><p>If you want to be a runner, spend time with runners. If you aspire to be an entrepreneur, surround yourself with entrepreneurs. The people around you will influence your mindset, your actions and the path you take in life. It truly changes everything.</p><p>So, next time you’re looking at a new challenge or opportunity, consider who you’re spending your time with. Their influence might just help you see the world in a whole new light.</p><p>Here are a few photos from my trip to Leh:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vd1Gkl16Rb5StAvidP5Mjg.jpeg" /><figcaption>Finally I saw snowfall</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZQ6gdMEIuw4qjg3jcdvmQ.jpeg" /><figcaption>Drove ATV</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RtQ-UE6S0ZhjadUUb1GN2w.jpeg" /><figcaption>Turtuk: Last village of India on the Indo-Pak border</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsJXFR86g5MSuUeVINcXzw.jpeg" /><figcaption>Bliss at Pangong lake</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1M_-7chJuiEyvrcX_UErGA.jpeg" /><figcaption>At Rancho’s school ladakh</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0gMCs6KKvO48hGHVBNZfA.jpeg" /><figcaption>Shanti Stupa</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjNj3rmKhmD45ADXzLToBw.jpeg" /><figcaption>Since I was in Leh, I had to check off riding a bike on the Ladakh roads</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fyD6mZC2NL6nKQ_5kv6Fkg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7kLtDxqW5G2clXQnMNoXQ.jpeg" /><figcaption>At the finish line, and a reminder to myself to take on the Khardung La Challenge</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f42YFXjGOowAp2bORnYseQ.jpeg" /></figure><p><em>Originally published at </em><a href="https://lulaguide.substack.com/p/running-a-half-marathon-in-ladakh"><em>https://lulaguide.substack.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10e6d67f9644" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance Monitoring 101: What to Monitor and Why for a Faster, More Reliable Application]]></title>
            <link>https://medium.com/@ashok.tankala/performance-monitoring-101-what-to-monitor-and-why-for-a-faster-more-reliable-application-44df427b403d?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/44df427b403d</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[performance-monitoring]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[latency]]></category>
            <category><![CDATA[system-performance]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 12:42:46 GMT</pubDate>
            <atom:updated>2024-09-02T12:42:46.363Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Performance?</h3><p>The responsiveness of a software application in meeting user requirements on a given hardware setup and load(volume of requests).</p><p>When you get a complaint saying your application is running slow, if your default answer is to increase the server capacity but never monitor your application then it might get you off the hook once or twice but eventually you will have a hard time.</p><p>That’s why you need to monitor your application performance.</p><blockquote>“What gets measured gets improved<em>.” — Peter Drucker</em></blockquote><p>If you want to improve your application’s performance then the first step is to measure it.</p><h3>What does the Performance problem look like?</h3><p>It is somewhat similar to a traffic jam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mycx7AEVq9Bv_jnA.png" /></figure><p>When one vehicle (request) gets stuck, it causes others to get stuck as well. This affects many vehicles (requests) that follow the same route (server), causing them to experience delays even after the initial vehicle has long passed.</p><ol><li><strong>Inefficient Coding</strong></li></ol><blockquote>Bad business logic, Memory Leaks, Unoptimized Queries, Choosing wrong data structures, Lack of Caching, Serial Processing, etc</blockquote><p><strong>2. Configuration Issues</strong></p><blockquote>Load Balancer Misconfiguration, Incorrectly configured thread pools, Incorrect memory allocation, etc</blockquote><p><strong>3. Insufficient resource capacity</strong></p><blockquote>Insufficient CPU or Memory, Disk I/O Bottlenecks, Network Latency, Server Overload, etc</blockquote><p><strong>4. Environmental Factors</strong></p><blockquote>Slow or unreliable Third-Party Services, OS patches/Software Updates, An unexpected spike or usage in user activity, Security issues like DDoS Attacks, Malware, etc</blockquote><h3>Objective</h3><p>Usually, our objective is to improve performance, which will be to Minimise latency between Request &amp; Response and Maximise Throughput with Concurrency.</p><p>A simple application architecture looks like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*7_6Eoj072zfvNklF.png" /></figure><h4>What is latency?</h4><p>The delay between a request and its corresponding response.</p><p>Latency = Wait time (Waiting time for this request to pick up at multiple components of the system like Each Microservice, Database, etc) + Processing Time (Time taken at the time of processing in multiple components of the system)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*b1hT9CZzL80rhku0.png" /></figure><p>Here the dotted lines represent processing time and the continuous line is the wait time. Here the latency is</p><p>Latency = 1010 milli seconds (100 + 30 + 10 + 150 + 10 + 200 + 10 + 300 + 10 + 50 + 10 + 20 + 10 + 100)</p><h4>What is Throughput?</h4><p>The amount of work the application can process within a given time frame. This is often measured in transactions per second, requests per second or data processed per unit of time.</p><p>Throughput depends on Latency &amp; Hardware Capacity.</p><h4>What is Concurrency?</h4><p>The ability of a system to handle multiple tasks or operations at the same time. We can say how many tasks are in progress simultaneously, whether they are executing fully in parallel (on multiple processors) or are interleaved in time (on a single processor).</p><h3>Performance Monitoring Themes</h3><p>There is kind of 4 themes to monitor an application.</p><ol><li><strong>Latency</strong></li></ol><blockquote>Because it affects user experience. It should be as low as possible.</blockquote><p>Based on several studies conducted every second delay in your page leads to 11% fewer page views, a 16% decrease in customer satisfaction &amp; 7% loss in conversions. <br>More than 10 years ago, Amazon found that every 100ms of latency cost them 1% in sales.</p><p><strong>2. Throughput</strong></p><blockquote>It will give us a fair idea of how many users the application serves/support. It should be higher than the peak time traffic.</blockquote><p>Note: Concurrency is a great thing to have but without great throughput, it doesn’t matter that much. In the process of concentrating throughput, we touch concurrency too so as a theme throughput makes sense.</p><p><strong>3. Errors</strong></p><blockquote>This is self-explanatory and we all strive to make it 0 but it is an almost impossible task so it should be as little as possible. It’s better to track in percentage terms.</blockquote><p>At the time of testing, it’s ok to have time-out errors, not functionality errors.</p><p><strong>4. Resource Utilisation</strong></p><blockquote>How our hardware or you can say cloud resources are utilised whether they are touching 100% of their capacity or at the permissible level. If we don’t monitor them then we will get surprises like the disk is full or memory full or 100% CPU issue or the Network is choked, etc. Sometimes there is a chance we are underutilising it then we are unnecessarily paying the bill.</blockquote><p><strong><em>One more thing we need to look into is Tail Latency.</em></strong> It is part of Latency only but many times we see it from an average lens because of that we miss this part and most of the future problems linger in the Tail Latency area only.</p><h4>What is Tail Latency?</h4><p>The latency experienced by the slowest or “tail end” of requests in a system. It’s a measure of the worst-case performance, often expressed as the 95th, 99th, or 99.9th percentile of response times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*LxpTT36UeoH5E2MV.png" /></figure><p>In simpler terms, tail latency is concerned with the delays that occur in the slowest 1%, 0.1%, or even 0.01% of requests. These requests take much longer to process compared to the majority, and although they are few, they can significantly impact the overall user experience, especially in large-scale systems.</p><h3>Key Metrics to Monitor</h3><p>Monitoring the key metrics of your application’s performance is important to keep them running smoothly. These differ from your application type. If it is for a mobile application then we look at different metrics for a web application we look at different ones. In the web application also we will monitor different metrics for frontend &amp; backend.</p><blockquote><em>“You can’t manage what you can’t measure.” — Peter Drucker</em></blockquote><p>If you monitor your application well you can identify issues before users complain, optimize performance and resource utilization and make informed decisions to improve the user experience and of course, achieve business objectives.</p><h4>1. Requests rate</h4><p>The request rate refers to the number of requests your application or servers receive within a particular time period. Monitoring this metric helps you understand the load on your system and track how it changes over time. A sudden spike in request rate could indicate increased user activity or potentially harmful events like a DDoS attack.</p><h4>2. Response Time</h4><p>Response time is the duration it takes for your application to respond to a user request. Monitoring average and tail response times (e.g., 95th or 99th percentile) provides insights into how quickly your system is responding to users. High response times can indicate performance bottlenecks in your application.</p><h4>3. Error rate</h4><p>Error rate measures the percentage of requests that result in errors. This could be HTTP errors (e.g., 4xx or 5xx status codes) or application-specific errors. A rising error rate is often a red flag that needs immediate attention, as it can indicate failing services or broken functionality.</p><h4>4. Throughput</h4><p>Throughput refers to the number of transactions or operations your application can handle within a given period. High throughput is desirable, but it must be balanced with response time to ensure a good user experience.</p><h4>5. Resource Utilization</h4><p>Resource utilization metrics, such as <strong>memory, CPU, disk, and network usage</strong>, provide a clear picture of how efficiently your application is using its resources. Monitoring these helps prevent over-utilization or under-utilization, both of which can lead to performance issues.</p><h4>6. Disk I/O</h4><p>Disk I/O measures the speed at which data is read from or written to the disk. High disk I/O can indicate bottlenecks, especially in database-heavy applications. Monitoring this metric helps in identifying issues with storage subsystems.</p><h4>7. Database Query Performance</h4><p>Monitoring the performance of your database queries is essential, especially for applications with heavy database interactions. Metrics such as query response time, slow queries and the number of queries per second help you identify and optimize inefficient database operations.</p><h4>8. Network Latency</h4><p>Network latency is the time it takes for data to travel from the user to the server and back. High latency can lead to poor user experience, especially in real-time applications. Monitoring network latency helps in identifying network issues or slowdowns.</p><h4>9. Tail Latency</h4><p>Tail latency focuses on the slowest requests, often measured at the 95th, 99th, or 99.9th percentile. Monitoring tail latency is critical because it reveals the worst-case performance scenarios that can severely impact user experience.</p><h4>10. Uptime/Downtime</h4><p>Uptime measures the amount of time your application is available and operational. Monitoring uptime and downtime is crucial for maintaining high availability and meeting service-level agreements (SLAs). Automated alerts for downtime can help you respond quickly to outages.</p><h4>11. Apdex Score</h4><p>The Apdex (Application Performance Index) score is a user satisfaction metric that ranges from 0 to 1. It is calculated based on the response times and the percentage of requests that meet a predefined performance threshold. Monitoring the Apdex score helps you gauge overall user satisfaction with your application.</p><h4>12. Session Duration and User Engagement</h4><p>For applications where user engagement is key, monitoring session duration and how users interact with the application can provide valuable insights. This data helps you understand user behaviour, optimize the user journey, and improve retention.</p><blockquote><em>If you are focusing on frontend of the application then the key metrics would be </em><strong><em>Page Load Time, First Contentful Paint (FCP), Time to Interactive (TTI), Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), JavaScript Execution Time, First Input Delay (FID), Error Rates (JavaScript Errors), Render Time, API Response Times, User Engagement Metrics, Bounce Rate and Heatmaps.</em></strong></blockquote><blockquote><em>If you are focusing on mobile app then the key metrics would be </em><strong><em>App Load Time, Time to First Interaction, App Crash Rate, Crash-Free Sessions, Battery Usage, Memory Usage, Network Latency, API Response Time, Error Rate, User Retention Rate, In-App Purchases, User Engagement Metrics, App Store Ratings and Reviews, and Push Notification Engagement.</em></strong></blockquote><p>Did I miss anything? If yes, Please help me make it better by sharing your thoughts in the comments. <br>👋 Let’s be friends! Follow me on <a href="https://x.com/ashok_tankala">Twitter</a> and connect with me on <a href="https://www.linkedin.com/in/ashoktankala/">LinkedIn</a>. Don’t forget to Subscribe as well.</p><p><em>Originally published at </em><a href="https://lulaguide.substack.com/p/performance-monitoring-101-what-to">https://lulaguide.substack.com/p/performance-monitoring-101-what-to</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44df427b403d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching 101: A Beginner’s Guide]]></title>
            <link>https://medium.com/@ashok.tankala/caching-101-a-beginners-guide-4f1312c0505c?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f1312c0505c</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[high-performance-apps]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 22 Jul 2024 08:58:19 GMT</pubDate>
            <atom:updated>2024-07-22T08:58:19.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjE56oR1k9QbhPSIM0GNXA.png" /></figure><p>Caching is a very important strategy in computing and web development that involves storing copies of data or computational results in a temporary storage area, called a cache.</p><p>Cache doesn’t exist only in the software world, it exists in many places in our day-to-day life. Our brain caches frequently needed stuff in the hippocampus like where we keep our vehicle keys &amp; etc.<br>In the kitchen, we keep frequently used stuff like salt, sugar, etc in nearby kitchen cabinet in smaller quantities.</p><p>This storage (Cache) allows for faster access to data &amp; more efficient processing. Before we understand What is Caching and how to implement it, let’s understand why we need to use it.</p><h4>Why Do We Need Caching?</h4><p>An Application with a smaller user base always feels fast. But the moment you hit a decent user base, your application becomes slow.</p><p>Based on several studies conducted every second delay in your page leads to 11% fewer page views, a 16% decrease in customer satisfaction &amp; 7% loss in conversions.<br>More than 10 years ago, Amazon found that every 100ms of latency cost them 1% in sales.</p><p>If your application is not performant you are losing your users/customers and revenue. There are many ways to make your application faster and one of the best ones is Caching.</p><p>I hope you are aware of <strong>The Pareto principle</strong>. Roughly 80% of consequences come from 20% of causes (the “vital few”). It applies to your Application as well.<br>Most of the users access the same data most of the time which can be Cached so that you don’t need to query from the database each time or run some business logic each time a user requests for that same data that was requested by another user a couple of milliseconds ago.</p><p>Because of Caching we can improve <strong>Application performance</strong>, <strong>Reduce network load</strong> &amp; <strong>better user experience</strong>.</p><h4>What is Cache?</h4><p>According to Wikipedia, “A cache is a block of memory that stores data that’s likely to be used again.”</p><p>I am guessing so far what I mentioned gave you a fair idea about What is Cache. Let’s understand from a Software application perspective.</p><p>Usually, a simple web application looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*KhB1pc02PVBa7WPZ.png" /></figure><p>Of course, in between load balancer &amp; many things will come but just for simplicity’s sake, we are sticking with it.</p><p>When a client sends a request to the application it goes to the server (our service), which then retrieves data from the database and sends it back to the client. In between any logic needs to be executed that will be done at our service/server level.</p><p>When there is a huge surge in users then it leads to slowness at the Database level because data needs to be retrieved from its storage which leads to performance degradation.</p><p>When we add Cache to this system it helps in overcoming this problem. When something is requested by a user our service checks the Cache if it is present then it gives it back to the user if not then retrieves it from the database, stores it in the cache (for future use) and gives it back to the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*7AngmbZHvgDEgLqs.png" /></figure><p>You might get doubt like even cache also stores somewhere and gives it back right why it is fast. As mentioned in the definition Cache stores the data in the memory(RAM) retrieval from it is much faster than accessing from storage systems(Hard disk).</p><p>Cache is like a Hashmap &amp; Storage is like an ArrayList.</p><p>A couple of things to remember about Cache:</p><ol><li>The cache uses memory so you can’t keep everything there because it’s expensive with respect to cost so we store only frequently accessed. If you don’t do this efficiently we will lose this advantage.</li><li>Data in the Cache is stored in memory so the moment we restart it that data is gone. Of course, there are ways to persist it but keeping this in mind is important to design a system better.</li></ol><h4>Where can Cache be used?</h4><p>It can be used in multiple places. This pic will give you some idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KH98CjP1uVGF6lS3.png" /></figure><p><strong>Client Side Cache<br></strong>Browsers usually keep the images after it downloaded at the time of page loaded. On the next page, if the same image is needed then it pics from the cache. Open any good website then open the Network tab in browser developer tools and go to the next page on that website you can observe that a bunch of images, fonts &amp; etc picked from the memory cache.</p><p>By the way, we store some of the things like the user’s name, role &amp; etc in Session level or cookies so that we can utilise the data instead of requesting from the server each time. Data at the Session level is usually stored in Local storage or Session storage or IndexedDB or cookies.</p><p><strong>CDN Caching</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aLPeRfCb3h1U0NjK.png" /></figure><p>Source: Scaleflex Blog</p><p>CDNs are a geographically distributed network of servers (Edge Servers). These servers deliver content from the nearest server to the user’s location. It reduces the time taken to access the content, resulting in a faster-loading website. Websites like Netflix use CDN caching extensively to give a great experience to the users.</p><p>CDN caching helps B2C sites especially. You can serve static pages, images, videos and many static assets from CDN which will give a great experience to the users by loading the website faster.</p><p><strong>Application Server Cache<br></strong>we can kind of say it is In-memory Caching. We either add this cache in in-memory alongside the application server or a separate server/service like Redis and Memcached.</p><p>If your application is very popular then you will use Distributed cache. In the Distributed cache each node(server) will have a part of the whole cache space and then using the consistent hashing function each request can be routed to where the cache request can be found.</p><p>Here we store frequently accessed data blocks, query results, metadata and session-specific information to reduce disk reads and query execution time, which results in faster response times.</p><p>Most of the developers spend a good amount of time on this.</p><p>Other caches are <strong>Database Caching, Web Server Caching, API Gateway Caching, etc</strong>.</p><h4>Cache writing strategies</h4><p>Writing data to the caching should be planned well based on your application needs, or else we will put unnecessary load on the Database or Cache which results in performance issues.</p><p>These are some of the popular writing strategies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yqxd3YcEvDHUA6Ma.png" /></figure><ol><li><strong>Write-around cache:</strong> In this strategy, we just write stuff in the Database directly. We don’t touch the cache at the time of write. In this strategy, Cache won’t be overwhelmed by write operations. Whenever the user wants some data application first reads from the cache if it’s not present it is called “Cache miss”, Then the application reads it from the Database and updates it in the Cache. Many people introduce Caching in their applications using this strategy.</li><li><strong>Write-through cache:</strong> In this strategy, the Application writes the data in Cache &amp; Database simultaneously. Write will be slow but read will be always fast and data will be consistent (same stays in Cache &amp; Database).</li><li><strong>Write-behind(Write-back) cache:</strong> In this strategy, the Application writes the data in the Cache. Data will be stored in the Database by Cache asynchronously (periodically or on certain events like eviction events). This strategy makes sense for write-heavy applications and ok with eventual consistency.</li></ol><h4>Cache reading strategies</h4><ol><li><strong>Cache Aside:</strong> In this strategy, whenever the user wants some data application first reads from the cache if it’s not present it is called “Cache miss”, Then the application reads it from the Database and updates it in the Cache. This is a common read strategy. That’s why used this strategy at the time of making writing strategy images.</li><li><strong>Read Through:</strong> In this strategy, the Application reads from the cache if the data is there it returns, if not there Cache gets it from the Database, sets it in the Cache and gives it back.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*7AcMzej4kSq-ciHl.png" /></figure><h4>Cache eviction and Invalidation strategies</h4><p>Removing data from the Cache is important or else we will face 2 problems.</p><ol><li>Server memory space will get occupied slowly.</li><li>Stale data (Eventually every data gets old because sometimes we update data by SQL queries or some other way where we forget to update the cache).</li></ol><p>Based on the strategy, the items will be removed whenever the server needs space. These are some of the popular strategies:</p><ol><li><strong>Least Recently Used (LRU):</strong> The most commonly used strategy. The title says it all. In this policy, it removes the items you didn’t use for a long time. Let me give you an example. You bought popcorn 3 months back by thinking you would eat it when you watch a movie at your home but you didn’t touch it at all. When the server needs space it removes these kinds of items in this strategy.</li><li><strong>Least Frequently Used (LFU):</strong> It sounds similar to LRU but there is a difference. In this policy, it removes the items you use once in a blue moon. For example, Fancy dinnerware or Air Fryer (I bought it thinking of making healthy food but I use it once in 6 months so eventually my mom put it outside of the kitchen 😜).</li><li><strong>First In, First Out (FIFO):</strong> The name says it all. It’s like a queue. The oldest item will get removed first when space is needed.</li><li><strong>Window TinyLFU (W-TinyLFU):</strong> It is somewhat the best of both worlds (LRU &amp; LFU). It keeps the most relevant cache entries in the cache by considering both how recent and how frequently the data has been accessed.</li><li><strong>Time To Live (TTL):</strong> We put the expiry date (Time to live) with each time. Whenever that time touches item will be removed. It is like when any item hits the expiry date no matter how frequently used &amp; favourite we will remove right like that. If you want your data regularly updated in Cache then this is a go-to strategy.</li></ol><h4>A Simple Example Application (How to implement it?)</h4><p>We will take a simple use case which is the White labelling use case. An Organisation can customise the theme. If they don’t, the default theme will be considered for that organisation.</p><p>Multiple users belong to one organisation. When users log in and open any page, the application needs to show the data based on that organisation theme. Usually, these values won’t be changed often so there is no point in querying them on every request so it is good to cache them.</p><p>Whenever theme details are needed we will check the Cache if it’s there we will serve from it if not (It is called a Cache miss) we will query the database, store it in the Cache and return it to the user/FrontEnd/Originator.</p><p>If any one of the users of a company changes the theme value before we store it in the Database we will simply evict that organisation’s theme in the Cache so that new changes will be picked from the Database and reflected to all the users in that organisation.</p><p>I made a simple example application in Python. You can find the code <a href="https://github.com/tankala/system-design-concepts/tree/main/caching">here</a>.</p><p>If you open the home page and choose a user then based on that user’s organisation the colour scheme and content will be changed. The theme data is picked from Cahe. If the theme values are changed then they will be deleted from the Cache. Here I used the Write-around strategy for writing &amp; Cache Aside strategy for reading.</p><p>To create the required data you can check <a href="https://github.com/tankala/system-design-concepts/blob/main/caching/db/white-labeling-db-create.sql">this SQL</a> file. We have 3 tables(organisations, users, themes).</p><p>We used these Python packages for this application:</p><pre>Flask<br>Flask-SQLAlchemy<br>redis<br>psycopg2-binary<br>python-dotenv</pre><p>I am using the <strong>Flask</strong> framework for this application. For the UI part will use <strong>jinja2</strong> templating, this comes by default with Flask so no need to install it.</p><p>Going to use <strong>SQLAlchemy</strong> for the DB part, <strong>Flask-SQLAlchemy</strong> is one of the best packages to handle SQLAlchemy stuff in the Flask application.</p><p><strong>redis</strong> package is Redis Python Client. <strong>psycopg2-binary</strong> package is the most popular PostgreSQL database adapter for the Python programming language. I am using PostgreSQL if you want to use some other SQL database and don’t forget to change the adapter package of it. <strong>python-dotenv</strong> package is for reading the .env file, I stored SQL URI and Redis server details in the .env file.</p><p>On the home page, we can select a user. Based on the user’s organisation UI colour scheme and the content will be changed. Home page looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/0*L8MVJbDFts5mhuCQ.png" /></figure><p>If you select another user it looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*TL-8LbSek7unKP4w.png" /></figure><p>home page(index.html) code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;{{ theme.title }}&lt;/title&gt;<br>    &lt;style&gt;<br>        h1 {<br>            color: {{ theme.styles.h1_color }};<br>        }<br>        h2 {<br>            color: {{ theme.styles.h2_color }};<br>        }<br>        p {<br>            color: {{ theme.styles.p_color }};<br>        }<br>    &lt;/style&gt;<br><br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script&gt;<br>        $(document).ready(function() {<br>            $(&#39;#organisation_id&#39;).change(function() {<br>                var selectedOrgId = $(this).val();<br>                $.ajax({<br>                    url: &#39;/get-theme/&#39; + selectedOrgId,<br>                    method: &#39;GET&#39;,<br>                    success: function(response) {<br>                        let new_theme = response;<br>                        updateTheme(new_theme);<br>                    },<br>                    error: function() {<br>                        console.log(&#39;Error in fetching organisation details&#39;);<br>                    }<br>                });<br>            });<br>            function updateTheme(theme) {<br>                $(&#39;h1&#39;).css(&#39;color&#39;, theme.styles.h1_color);<br>                $(&#39;h2&#39;).css(&#39;color&#39;, theme.styles.h2_color);<br>                $(&#39;p&#39;).css(&#39;color&#39;, theme.styles.p_color);<br>                $(&#39;header h1&#39;).text(theme.header);<br>                $(&#39;main h2&#39;).text(&#39;Welcome to the website!&#39;);<br>                $(&#39;main p&#39;).text(theme.content);<br>            }<br>        });<br>    &lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;label for=&quot;organisation_id&quot;&gt;Users:&lt;/label&gt;<br>    &lt;select id=&quot;organisation_id&quot; name=&quot;organisation_id&quot;&gt;<br>        &lt;option value=&quot;&quot;&gt;Select a User&lt;/option&gt;<br>        {% for user in users %}<br>            &lt;option value=&quot;{{ user.organisation_id }}&quot;&gt;{{ user.name }}&lt;/option&gt;<br>        {% endfor %}<br>    &lt;/select&gt;<br>    &lt;header&gt;<br>        &lt;h1&gt;{{ theme.header }}&lt;/h1&gt;<br>    &lt;/header&gt;<br>    &lt;main&gt;<br>        &lt;h2&gt;Welcome to the website!&lt;/h2&gt;<br>        &lt;p&gt;{{ theme.content }}&lt;/p&gt;<br>    &lt;/main&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>At the start, it is powered by the default theme when we change the user from the dropdown using jQuery hitting the “get-theme” API based on the response changing the CSS &amp; content.</p><p>We can change the theme values using the theme page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LI6r3H2vi2c7z1b9.png" /></figure><p>Based on the organisation you selected you can change the theme details.</p><p>Theme Page Code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Theme Selector&lt;/title&gt;<br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script&gt;<br>        $(document).ready(function() {<br>            $(&#39;#id&#39;).change(function() {<br>                var selectedOrgId = $(this).val();<br>                $.ajax({<br>                    url: &#39;/get-theme/&#39; + selectedOrgId,<br>                    method: &#39;GET&#39;,<br>                    success: function(response) {<br>                        if (response.organisation_id != selectedOrgId) {<br>                            $(&#39;#title&#39;).val(&#39;&#39;);<br>                            $(&#39;#header&#39;).val(&#39;&#39;);<br>                            $(&#39;#content&#39;).val(&#39;&#39;);<br>                            $(&#39;#h1_color&#39;).val(&#39;&#39;);<br>                            $(&#39;#h2_color&#39;).val(&#39;&#39;);<br>                            $(&#39;#p_color&#39;).val(&#39;&#39;);<br>                        } else {<br>                            $(&#39;#title&#39;).val(response.title);<br>                            $(&#39;#header&#39;).val(response.header);<br>                            $(&#39;#content&#39;).val(response.content);<br>                            $(&#39;#h1_color&#39;).val(response.styles.h1_color);<br>                            $(&#39;#h2_color&#39;).val(response.styles.h2_color);<br>                            $(&#39;#p_color&#39;).val(response.styles.p_color);<br>                        }<br>                    },<br>                    error: function() {<br>                        console.log(&#39;Error in fetching organisation details&#39;);<br>                    }<br>                });<br>            });<br>        });<br>    &lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Please enter theme details of organisation&lt;/h1&gt;<br>    &lt;form action=&quot;/set-theme&quot; method=&quot;POST&quot;&gt;<br>        &lt;label for=&quot;id&quot;&gt;Organisation:&lt;/label&gt;<br>        &lt;select id=&quot;id&quot; name=&quot;id&quot;&gt;<br>            &lt;option value=&quot;&quot;&gt;Select an organisation&lt;/option&gt;<br>            {% for org in organisation_list %}<br>            &lt;option value=&quot;{{ org.id }}&quot;&gt;{{ org.name }}&lt;/option&gt;<br>            {% endfor %}<br>        &lt;/select&gt;<br>        &lt;br/&gt;<br><br>        &lt;label for=&quot;title&quot;&gt;Title:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;title&quot; name=&quot;title&quot;&gt;<br>        &lt;br/&gt;<br><br>        &lt;label for=&quot;header&quot;&gt;Header:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;header&quot; name=&quot;header&quot;&gt;<br>        &lt;br/&gt;<br><br>        &lt;label for=&quot;content&quot;&gt;Content:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;content&quot; name=&quot;content&quot;&gt;<br>        &lt;br/&gt;<br><br>        &lt;label for=&quot;h1_color&quot;&gt;H1 Color:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;h1_color&quot; name=&quot;h1_color&quot;&gt;<br>        &lt;br/&gt;<br>        <br>        &lt;label for=&quot;h2_color&quot;&gt;H2 Color:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;h2_color&quot; name=&quot;h2_color&quot;&gt;<br>        &lt;br/&gt;<br>        <br>        &lt;label for=&quot;p_color&quot;&gt;P Color:&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;p_color&quot; name=&quot;p_color&quot;&gt;<br>        &lt;br/&gt;<br><br>        &lt;button type=&quot;submit&quot;&gt;Apply Theme&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>To get theme details similar to index.html. To set the theme we are using form which sends data to the “set-theme” API.</p><p>The whole Backend logic is written in the app.py only for simplicity’s sake.</p><p>At the start, we need to set the SQL connection through SQLAlchemy &amp; Redis Connection.</p><pre>load_dotenv()<br><br>app = Flask(__name__)<br><br># Connect to the database using the connection string from the environment variables<br>app.config[&#39;SQLALCHEMY_DATABASE_URI&#39;] = os.getenv(&#39;DATABASE_URL&#39;)<br>db = SQLAlchemy(app)<br><br># Connect to Redis using the connection details from the environment variables<br>redis_host = os.getenv(&#39;REDIS_HOST&#39;)<br>redis_port = os.getenv(&#39;REDIS_PORT&#39;)<br>redis_password = os.getenv(&#39;REDIS_PASSWORD&#39;)<br>redis_db = os.getenv(&#39;REDIS_DB&#39;)<br>redis = Redis(host=redis_host, port=redis_port, password=redis_password, db=redis_db)</pre><p>We need a default organisation which will be for the organisations that didn’t choose the theme. Its id will be 1.</p><pre>DEFAULT_ORGANISATION_ID = 1</pre><p>We need all the users, organisations lists to show in the UI, that code looks like this</p><pre>def get_users():<br>    users = db.session.execute(text(&quot;SELECT * FROM users&quot;)).fetchall()<br>    return users<br><br>def get_organisations():<br>    organisations = db.session.execute(text(&quot;SELECT * FROM organisations&quot;)).fetchall()<br>    return organisations</pre><p>home page, theme page routes code</p><pre>@app.route(&quot;/&quot;)<br>def home():<br>    users = get_users()<br>    theme = get_theme()<br>    return render_template(&quot;index.html&quot;, users=users, theme=theme)<br><br>@app.route(&quot;/theme&quot;)<br>def theme():<br>    organisations = get_organisations()<br>    return render_template(&quot;theme.html&quot;, organisation_list=organisations)</pre><p>To get the theme of an organisation we need to get it from Cache if it’s there or else we need to get it from the database and set it in the Cache. We are using the <strong>Cache Aside</strong> reading strategy. Getting it from the Cache and setting it in the Cache part is common for any functionality in the application where the Cache makes sense. Decorator makes a lot of sense for this part of the functionality. So created a cache_decorator for it</p><pre>def cache_decorator(func):<br>    @wraps(func)<br>    def wrapper(*args, **kwargs):<br>        # Check if the data is present in cache<br>        cache_key = f&quot;cache:{func.__name__}:{args}:{kwargs}&quot;<br>        cached_data = redis.get(cache_key)<br><br>        if cached_data:<br>            # Data is present in cache, return it<br>            return json.loads(cached_data)<br><br>        # Data is not present in cache, execute the function<br>        result = func(*args, **kwargs)<br><br>        # Set the result in cache<br>        redis.set(cache_key, json.dumps(result))<br><br>        return result<br><br>    return wrapper</pre><p>“get-theme” route code</p><pre>@app.route(&quot;/get-theme/&lt;organisation_id&gt;&quot;)<br>@cache_decorator<br>def get_theme(organisation_id=DEFAULT_ORGANISATION_ID):<br>    theme_db = db.session.execute(text(f&quot;SELECT * FROM themes WHERE organisation_id = {organisation_id}&quot;)).fetchone()<br><br>    theme = {}<br>    if theme_db:<br>        theme[&#39;organisation_id&#39;] = theme_db[1]<br>        theme[&#39;title&#39;] = theme_db[2]<br>        theme[&#39;header&#39;] = theme_db[3]<br>        theme[&#39;content&#39;] = theme_db[4]<br>        theme[&#39;styles&#39;] = json.loads(theme_db[5])<br>    else:<br>        return get_theme()<br>    <br>    return theme</pre><p>At the time of setting the theme we need to store it in the database and also evict it from the Cache or else old data will be served. This functionality code you can find below</p><pre>@app.route(&quot;/set-theme&quot;, methods=[&#39;POST&#39;])<br>def set_theme():<br>    organisation_id = request.form[&#39;id&#39;]<br>    title = request.form[&#39;title&#39;]<br>    header = request.form[&#39;header&#39;]<br>    content = request.form[&#39;content&#39;]<br>    h1_color = request.form[&#39;h1_color&#39;]<br>    h2_color = request.form[&#39;h2_color&#39;]<br>    p_color = request.form[&#39;p_color&#39;]<br><br>    styles = json.dumps({<br>        &quot;h1_color&quot;: h1_color,<br>        &quot;h2_color&quot;: h2_color,<br>        &quot;p_color&quot;: p_color<br>    })<br><br>    theme = db.session.execute(text(f&quot;SELECT * FROM themes WHERE organisation_id = {organisation_id}&quot;)).fetchone()<br>    # Evict the cache for the get_theme function<br>    # redis.delete(&#39;&quot;cache:get_theme:():{&#39; + &quot;&#39;organisation_id&#39;:&#39;&quot; + str(organisation_id) + &quot;&#39;}&quot; + &#39;&quot;&#39;)<br>    redis.delete(f&quot;cache:get_theme:():{{&#39;organisation_id&#39;: &#39;{organisation_id}&#39;}}&quot;)<br><br>    if theme:<br>        # Theme already exists, update it<br>        db.session.execute(text(f&quot;UPDATE themes SET title = &#39;{title}&#39;, header = &#39;{header}&#39;, content = &#39;{content}&#39;, styles = &#39;{styles}&#39; WHERE organisation_id = {organisation_id}&quot;))<br>    else:<br>        # Theme doesn&#39;t exist, insert it<br>        db.session.execute(text(f&quot;INSERT INTO themes (organisation_id, title, header, content, styles) VALUES ({organisation_id}, &#39;{title}&#39;, &#39;{header}&#39;, &#39;{content}&#39;, &#39;{styles}&#39;)&quot;))<br><br>    db.session.commit()<br><br>    return &quot;Theme set successfully&quot;</pre><p>You will find the whole application code <a href="https://github.com/tankala/system-design-concepts/tree/main/caching">here</a>.</p><h4>Cache Challenges you need to ponder about</h4><p>If you think once you implement Cache your world will be filled with Rainbows &amp; Unicorns then you are wrong. If you don’t implement it properly or your user base gets increased you will face some challenges due to Cache. Some of the popular ones are</p><ol><li><strong>Cache Consistency</strong>: In distributed systems, making sure data consistency across multiple caches can be challenging due to factors like network latency and node failures.<br>Let’s take an example. Let’s say we are showing the number of views of a page if there is inconsistency one user will see 10 and another user will get 8.<br>Ensure that the data seen by different parts of the system is up-to-date.</li><li><strong>Cache Pollution</strong>: When unnecessary or irrelevant data occupies cache space, it reduces the effectiveness of caching. Strategies such as eviction policies need to balance between keeping useful data and making room for new data.</li><li><strong>Cache Size and Placement</strong>: Determining the appropriate size and placement of caches is important to maximize hit rates (accessing data already in the cache) while minimizing miss penalties (having to fetch data from slower memory like Disk/Database). Also, make sure you don’t create Large Cache keys(<strong>Big Key</strong>) which will lead to slower lookups.</li><li><strong>Thundering Herd Problem</strong>: This occurs when multiple processes or threads are waiting for a particular Cache node(Server) to become available or to be updated. When it becomes available, all waiting processes or threads are awakened simultaneously, causing a sudden surge of requests. This can overwhelm caches and backend systems, leading to performance degradation or even system instability. Strategies to mitigate this problem include using techniques like throttling, caching responses or using queuing mechanisms to stagger requests.</li><li><strong>Hot Key Problem:</strong> Hot keys are critical in caching because caching systems are designed to accelerate access to frequently accessed data. However, hot keys can also pose challenges. If not managed properly, Several hot keys come under one Cache Node and that node will get the most of the requests which leads to performance bottlenecks, increased latency and potential cache thrashing.</li></ol><h4>Monitoring</h4><ol><li><strong>Hit Rate</strong>: Measure the percentage of requests that are served from the cache without needing to fetch data from slower storage.</li><li><strong>Miss Rate</strong>: Track the percentage of requests that result in cache misses and require fetching data from slower storage. This will give you a good idea about whether you should improve your Cache strategy or take a new approach. If there is any unusual pattern analyse it because it will give you a fair idea of the Security aspect also such as unusual or malicious access attempts.</li><li><strong>Eviction Rate</strong>: Monitor how often items are evicted from the cache due to space constraints or cache replacement policies.</li><li><strong>Cache Size and Capacity</strong>: Keep an eye on the current size of the cache and its capacity limits to ensure efficient usage of resources.</li><li><strong>Latency</strong>: Measure the time taken to serve cache hits and misses to understand performance implications.</li></ol><p>Did I miss anything? If yes, Please help me make it better by sharing your thoughts in the comments.<br>👋 Let’s be friends! Follow me on <a href="https://x.com/ashok_tankala">Twitter</a> and connect with me on <a href="https://www.linkedin.com/in/ashoktankala/">LinkedIn</a>. Don’t forget to Subscribe as well.</p><p>This article was originally published in my blog — <a href="https://lulaguide.substack.com/p/caching-101-a-beginners-guide">https://lulaguide.substack.com/p/caching-101-a-beginners-guide</a></p><p>Inspired by<br><a href="https://www.designgurus.io/blog/caching-system-design-interview">https://www.designgurus.io/blog/caching-system-design-interview</a><br><a href="https://blog.bytebytego.com/p/a-crash-course-in-caching-part-1">https://blog.bytebytego.com/p/a-crash-course-in-caching-part-1<br></a><a href="https://www.geeksforgeeks.org/caching-system-design-concept-for-beginners/">https://www.geeksforgeeks.org/caching-system-design-concept-for-beginners/</a><br><a href="https://aws.amazon.com/caching/">https://aws.amazon.com/caching/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f1312c0505c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Essential Skills for Software Engineers Beyond Coding]]></title>
            <link>https://medium.com/@ashok.tankala/essential-skills-for-software-engineers-beyond-coding-3329916f33a5?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/3329916f33a5</guid>
            <category><![CDATA[tech-leadership]]></category>
            <category><![CDATA[leadership-development]]></category>
            <category><![CDATA[career-growth]]></category>
            <category><![CDATA[unlock-potential]]></category>
            <category><![CDATA[executive-function]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 06:45:28 GMT</pubDate>
            <atom:updated>2024-07-08T06:45:28.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBGzkwuQmgDbuV8bmIr5pw.png" /></figure><p>When I started my career, I thought being great at coding was the main thing needed to become a top software engineer and achieve my dream of becoming a CTO. It took me a long time to realize that while coding is important, it’s not everything. Here are the skills I learned along the way that helped me grow. I hope they help you reach your goals faster and avoid the mistakes I made.</p><h4>1. Communication Skills 🗣️</h4><p>Being able to communicate well is crucial in any job, especially in software engineering. You need to explain your ideas clearly to avoid misunderstandings and save time. As you advance in your career, good communication helps improve teamwork and coordination.</p><h4>2. Teamwork and Helping Others 🤝</h4><p>At the start of my career, I underestimated the importance of being a good team member. I thought I could do everything on my own. But to create the best products, you need to work well with others and support your team.</p><h4>3. Leadership and Management Skills 👩‍💼👨‍💼</h4><p>Whether you’re leading a team or managing a project, leadership skills are essential. Great leaders inspire and guide their teams.</p><p>I will suggest having good mentors in your life. I learned a lot more from my mentors in this area than any book or session, especially in this area.</p><h4>4. Mastering the Basics 📚</h4><p>While technology keeps changing, the basic principles of software engineering stay the same. Having a strong foundation in these basics is very important. I was able to switch between different programming languages (Java, Node.js, Python, PHP, .Net, etc) because I understood the fundamentals well. The people I know who are very good in this field spent a lot of time mastering the fundamentals. Make sure you spend time mastering the basics whenever you learn something new.</p><h4>5. Always Learning and Being Adaptable 📖🌀</h4><p>The tech world moves fast. For a long time, I resisted new tools and stuck with what I knew. I used to defend Java like anything after 9 years into my career I understand how wrong I was and if I had been more adaptable I would have solved so many problems much better and in less time.</p><p>Being open to new tools and methods can help you solve problems more efficiently. Keep learning and stay adaptable to stay ahead in your career.</p><h4>6. Understanding Business and Solving Problems 🏢🧠</h4><p>It’s not enough to just be good at coding. You need to understand how your work fits into the bigger picture of the business to create solutions that help users. Remember, “If you don’t understand, you can’t solve.”</p><p>You also need to be good at solving all kinds of problems, not just coding ones. Tools are always improving, but your ability to solve problems is what matters.</p><p>Did I miss anything? Please share your thoughts to help make this list even better.</p><p>This article was originally published on my blog — <a href="https://lulaguide.substack.com/p/essential-skills-for-software-engineers">https://lulaguide.substack.com/p/essential-skills-for-software-engineers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3329916f33a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Waiting! Timely Feedback Drives Performance and Morale]]></title>
            <link>https://medium.com/@ashok.tankala/stop-waiting-timely-feedback-drives-performance-and-morale-7bf2e238d46d?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bf2e238d46d</guid>
            <category><![CDATA[leadership-mindset]]></category>
            <category><![CDATA[growth-mindset]]></category>
            <category><![CDATA[leadership-insights]]></category>
            <category><![CDATA[feedback-culture]]></category>
            <category><![CDATA[leadership-development]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 07:16:19 GMT</pubDate>
            <atom:updated>2024-06-24T07:16:19.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWOPHVdRfGJzc2v5UPo7GQ.png" /></figure><p>As a manager, you play an important role in guiding your team to success. One of the most important &amp; powerful things you can do is give feedback. But how you are going to do this make or break your team’s performance and morale. If you wait and give feedback at the time of Appraisal it becomes criticism, not feedback that’s why it’s always better to give early feedback. 🗣️💬</p><h4>The Problem with Late Criticism</h4><p>You sat down with one of your team members and started listing areas where he/she didn’t meet expectations. Your team member is caught off guard. They thought they were doing okay. Now, they’re facing a disappointing review and didn’t have a chance to improve earlier.</p><p>Nobody likes bad news, especially when it comes as a surprise. They will wonder why you didn’t tell them sooner so they could fix the issues.</p><h4>The Advantage of Early Feedback</h4><p>Early feedback, on the other hand, is like a gentle nudge in the right direction. When you notice a problem or see an opportunity for improvement, addressing it immediately gives your team member a chance to adjust their approach.</p><h4>Here’s why early feedback is beneficial:</h4><p><strong>1. Clarity and Focus:</strong> Regular feedback helps employees understand what they are doing well and where they need to improve. It sets clear expectations and keeps them focused on the right goals.📈🔍</p><p><strong>2. Boosted Morale:</strong> Knowing that their manager is paying attention and is invested in their growth can be incredibly motivating. It shows you care about their success.🚀💪</p><p><strong>3. Continuous Improvement:</strong> Small, timely corrections prevent bigger issues. It encourages a culture of learning and adaptability.🛠️🌱</p><h4>How to Give Effective Early Feedback:</h4><p><strong>1. Be Specific:</strong> Instead of saying, “You need to improve your work,” point out particular behaviours or results. For example, “I noticed that your last week’s mail to the client missed this key data. Let’s ensure we include that in the future.”📝</p><p><strong>2. Keep it Private:</strong> Feedback is best delivered in a one-on-one setting. This ensures that the conversation is constructive and focused on development, without the embarrassment of public criticism.🤝</p><p><strong>3. Be Balanced:</strong> Highlight what’s working well, not just what needs to be improved. Acknowledge their efforts and successes, which reinforces positive behaviours.🏆⚖️</p><p><strong>4. Follow-Up:</strong> After giving feedback, check in to see how the employee is progressing. Offer support and resources if needed. This shows your commitment to their improvement and helps build trust.📞👂</p><p>This article was originally published on my blog — <a href="https://lulaguide.substack.com/p/stop-waiting-timely-feedback-drives">https://lulaguide.substack.com/p/stop-waiting-timely-feedback-drives</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bf2e238d46d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Python Decorators]]></title>
            <link>https://python.plainenglish.io/understanding-python-decorators-6c3c8aafda90?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c3c8aafda90</guid>
            <category><![CDATA[decorators-in-python]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[functions-in-python]]></category>
            <category><![CDATA[free-python-tutorials]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 05:58:20 GMT</pubDate>
            <atom:updated>2024-06-10T08:51:44.472Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Decorators Everywhere" src="https://cdn-images-1.medium.com/max/1024/1*JaJdh-B_fuvtz53dxDOpFQ.jpeg" /></figure><p>Without using decorators I think mostly we can’t build a decent application. They are everywhere. Let’s learn what are they and how we can build our own.</p><p>If you use Flask or FastAPI or any framework to build API you use a decorator to create a route. If you are thinking of caching then the decorator is there or schedule a task for that also decorator is there like that the list goes on.</p><h3>But what exactly is Decorator?</h3><p>In simple words, you can say it’s just a function.</p><p>If you want me to explain in more words then we can say A Python decorator is a function that takes in a function and returns it by adding some functionality.</p><p>Decorator is an amazing feature of many programming languages which allows us to modify or extend the behaviour of functions or methods without changing their actual code.</p><p>If you want to do something before and after a function then Decorators are the best option to explore.</p><p>In the normal world, you can say decorators are like Front gate security at the office. What they care about is who is coming to the office, what they are taking to the office &amp; what they are taking from the office after their work is done. They don’t care what you are doing in the office.</p><p>Before understanding Decorator let’s understand Python functions a bit in depth so that we can understand Decorators a lot better.</p><h3>Let’s Understand Python Functions</h3><p>We all know what a function is: it takes arguments as input, does some work using it then returns a value.</p><h3>Functions are like First class citizens</h3><p>In functional programming, you work mostly with pure functions which don’t have side effects. By the way, Python supports many functional programming concepts, including treating functions as first-class objects. It means a function can be used as an input argument and also we can return a function.</p><h4>Function as an input argument</h4><pre>def entry_log(name):<br>   return f&quot;{name} entering into the office&quot;<br><br>def exit_log(name):<br>   return f&quot;{name} exiting from the office&quot;<br><br>def security_check(name, log_func):<br>   print(log_func(name))</pre><p>Here entry_log &amp; exit_log are normal functions which write regularly but the security_check function is not like that; it expects function as 2nd input arguments. So we can pass entry_log or exit_log to it.</p><pre>security_check(&quot;Ashok&quot;, entry_log)<br>security_check(&quot;Ashok&quot;, exit_log)</pre><p>Console Output:</p><pre>Ashok entering into the office<br>Ashok exiting from the office</pre><p>In these kinds of cases just remember to send the function name that’s it, brackets are not required if we add brackets means we are asking it to execute instead of passing it.</p><h4>Function as a Return Value</h4><p>Like we can send functions as input arguments we can return also. Let’s see the same example with a bit of change to see that in action.</p><pre>def entry_log(name):<br>   return f&quot;{name} entering into the office&quot;<br><br>def exit_log(name):<br>   return f&quot;{name} exiting from the office&quot;<br><br>def get_security_check_function(is_entering):<br>   if is_entering:<br>       return entry_log<br>   else:<br>       return exit_log<br><br>security_check = get_security_check_function(True)<br>print(security_check)<br>print(security_check(&quot;Ashok&quot;))<br><br>security_check = get_security_check_function(False)<br>print(security_check(&quot;Ashok&quot;))</pre><p>Console Output:</p><pre>&lt;function entry_log at 0x713ce62b3d90&gt;<br>Ashok entering into the office<br>Ashok exiting from the office</pre><p>Here also if you want to return a function then don’t add brackets to it. It basically returns that function; we can just execute that by adding brackets &amp; input arguments if required.</p><p>You can see the console log basically returns the reference to the function.</p><h4>Inner Functions (Function inside a Function)</h4><p>By the way, we can write functions under functions which are called inner functions. The inner functions scope will be up to the parent function level. It means we can’t call them from the outside. But the parent function wants then it can send its reference that we can call.</p><p>Let me show you an example:</p><pre>def parent():<br>   print(&quot;Printing from parent()&quot;)<br>   def child_function():<br>       print(&quot;Printing from child_function()&quot;)<br>  <br>   return child_function<br><br>child = parent()<br>print(&quot;Checking what&#39;s in the child: &quot;, child)<br>child()<br><br>child_function()</pre><p>Console Output:</p><pre>Printing from parent()<br>Checking what&#39;s in the child:  &lt;function parent.&lt;locals&gt;.child_function at 0x73680808a0e0&gt;<br>Printing from child_function()<br>Traceback (most recent call last):<br>  File &quot;/path/to/folder/check.py&quot;, line 61, in &lt;module&gt;<br>    child_function()<br>NameError: name &#39;child_function&#39; is not defined</pre><p>We called the parent function so its print statement runs &amp; then it just returns the child function.<br>If you see what got returned you can see the child_function reference but it clearly shows it’s under parent.<br>We can run it using brackets.</p><p>But if we want to call the child_function directly it will say it’s not defined because the child_function scope is up to the parent function only.</p><p>I hope you got a fair understanding of functions as First Class citizens/objects.</p><h3>Now let’s understand Decorators</h3><h3>Simple Decorator Example</h3><p>Let’s see a simple example &amp; understand</p><pre>def decorator(func):<br>   def wrapper():<br>       print(&quot;Before Function&quot;)<br>       func()<br>       print(&quot;After Function&quot;)<br>   return wrapper<br><br>def hello_world():<br>   print(&quot;Hello World!&quot;)<br><br>hello_world_function = decorator(hello_world)<br><br>hello_world_function()</pre><p>We just created a decorator function which takes the function as an argument and we are just wrapping whatever we want to do before and after the function call which came as an argument and returning that wrapper.</p><p>When we call the decorator function by giving the hello_world function as an argument we are getting the internal function wrapper so we are calling that function. We will get the output like this.</p><p>Console Output:</p><pre>Before Function<br>Hello World!<br>After Function</pre><p>If you understood this part then you kind of understood the decorator part totally.</p><h4>Let’s add Syntactic Sugar to it</h4><p>Now let’s see the magic. Instead of calling the decorator function by passing another function as an argument, let’s add syntactic sugar to it. Now the code looks like this.</p><pre>def decorator(func):<br>   def wrapper():<br>       print(&quot;Before Function&quot;)<br>       func()<br>       print(&quot;After Function&quot;)<br>   return wrapper<br><br>@decorator<br>def hello_world():<br>   print(&quot;Hello World!&quot;)<br><br>hello_world()</pre><p>What we did was add a decorator to the hello_world function. If you run this code same output comes.</p><p>See writing decorator is simple and the internal functionality also very simple.</p><p>Of Course, it is a simple version. We need to add a couple of whistles &amp; bells to it like if the passed function takes input arguments or returns something which also we should take care of.</p><h4>The Problem with this Approach</h4><p>This way we can play with decorators but this is not the right way because of this we will lose the metadata of the original function.</p><p>Let me show you an example</p><pre>def decorator(func):<br>   def wrapper():<br>       print(&quot;Before Function&quot;)<br>       func()<br>       print(&quot;After Function&quot;)<br>   return wrapper<br><br>@decorator<br>def hello_world():<br>   &#39;&#39;&#39;<br>   This is a function to print Hello World!<br>   &#39;&#39;&#39;<br>   print(&quot;Hello World!&quot;)<br><br>help(hello_world)</pre><p>If we write this code and execute the program we will get output like this</p><p>Console output:</p><pre>Help on function wrapper in module __main__:<br>wrapper()</pre><p>See the whole essence of the hello_world function gone. hello_world function doesn’t have a wrapper because of the decorator this wrapper function is coming. If you remove the decorator syntactic sugar part which is on top of the hello_world and run the help function it shows proper metadata. Like this.</p><p>Console output:</p><pre>Help on function hello_world in module __main__:<br>hello_world()<br>    This is a function to print Hello World!</pre><h4>The solution to it lies with @functools.wraps</h4><p>Now let’s write the decorator part properly.</p><pre>import functools<br><br>def decorator(func):<br>   @functools.wraps(func)<br>   def wrapper():<br>       print(&quot;Before Function&quot;)<br>       func()<br>       print(&quot;After Function&quot;)<br>   return wrapper<br><br>@decorator<br>def hello_world():<br>   &#39;&#39;&#39;<br>   This is a function to print Hello World!<br>   &#39;&#39;&#39;<br>   print(&quot;Hello World!&quot;)<br><br>hello_world()<br><br>help(hello_world)</pre><p>Same stuff just added the decorator. If you run this code you can see the proper output &amp; proper metadata of hello_world.</p><p>In this example, we are not taking care of the input arguments &amp; return part. So a good example code for a decorator is</p><pre>def decorator(func):<br>   @functools.wraps(func)<br>   def wrapper(*args, **kwargs):<br>       # Before Function tasks<br>       return_value = func(*args, **kwargs)<br>       # After Function tasks<br>       return return_value<br>   return wrapper</pre><h3>Some Real World Examples</h3><h4>Timing Decorator</h4><p>There are several places we can use. Usually, whenever we see some part of an application running slow we calculate the time at a bunch of places in which one is giving trouble so let’s write a decorator for it.</p><pre>import functools<br>import time<br><br>def calculate_time(func):<br>   @functools.wraps(func)<br>   def wrapper(*args, **kwargs):<br>       start_time = time.time()<br>       value = func(*args, **kwargs)<br>       end_time = time.time()<br>       run_time = end_time - start_time<br>       print(f&quot;{func.__name__}() took {run_time} secs&quot;)<br>       return value<br>   return wrapper<br><br>@calculate_time<br>def sum_of_numbers(limit):<br>   sum = 0<br>   for number in range(1, limit + 1):<br>       sum += number<br>   print(f&quot;Sum of numbers from 1 to {limit} is {sum}&quot;)<br><br>sum_of_numbers(999999)</pre><p>If you run this code you will get output like this.</p><p>Console Output:</p><pre>Sum of numbers from 1 to 999999 is 499999500000<br>sum_of_numbers() took 0.05221295356750488 secs</pre><p>Cool right. We made a cool decorator which calculates the time that function took.</p><p>We can pass arguments to the decorator also. We can write class-level decorators also like @dataclass. Like that, there are so many things we can do with decorators.</p><h4>Example for passing arguments to the decorator</h4><pre>import functools<br>import time<br><br>def slow_the_function(seconds=1):<br>   def decorator_code(func):<br>       @functools.wraps(func)<br>       def wrapper(*args, **kwargs):<br>           time.sleep(seconds)<br>           value = func(*args, **kwargs)<br>           print(f&quot;Slowed the {func.__name__}() for {seconds} seconds&quot;)<br>           return value<br>       return wrapper<br>   return decorator_code<br><br>@slow_the_function(seconds=2)<br>def sum_of_numbers(limit):<br>   sum = 0<br>   for number in range(1, limit + 1):<br>       sum += number<br>   print(f&quot;Sum of numbers from 1 to {limit} is {sum}&quot;)<br><br>sum_of_numbers(999999)</pre><p>In this case, the only problem is we need to write a bunch of nested functions other than that cool.</p><p>This article was originally published on my blog — <a href="https://newsletter.piptrends.com/p/understanding-python-decorators">https://newsletter.piptrends.com/p/understanding-python-decorators</a></p><h4>Reference:</h4><p><a href="https://www.programiz.com/python-programming/decorator">https://www.programiz.com/python-programming/decorator</a><br><a href="https://realpython.com/primer-on-python-decorators/">https://realpython.com/primer-on-python-decorators/</a><br><a href="https://www.geeksforgeeks.org/decorators-in-python/">https://www.geeksforgeeks.org/decorators-in-python/</a></p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c3c8aafda90" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/understanding-python-decorators-6c3c8aafda90">Understanding Python Decorators</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Goto Strategies for Beating Burnout & Healthier Work-Life Balance]]></title>
            <link>https://medium.com/@ashok.tankala/my-goto-strategies-for-beating-burnout-healthier-work-life-balance-550c8d7b7c8e?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/550c8d7b7c8e</guid>
            <category><![CDATA[worklife-balance]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[burnout]]></category>
            <category><![CDATA[self-betterment]]></category>
            <category><![CDATA[personal-growth]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 07:48:34 GMT</pubDate>
            <atom:updated>2024-06-03T07:48:34.746Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xrx6Ub6KItFncGoFQRYDVA.png" /></figure><p>Feeling burned out at work? Here are some strategies that have helped me:</p><p>1. Identify the Causes of Your Burnout 🔍<br> It might seem obvious, but pinpointing the exact reasons for your burnout can be challenging. It could stem from work stress, lack of sleep, office politics, dissatisfaction with personal life or concerns about career growth. Once you identify the root cause, it becomes easier to address.</p><p>2. Seek Guidance from a Mentor or Role Model 🌟<br> Talking to someone you look up to, such as a mentor or coach, can provide valuable insights. These individuals have often faced similar challenges and can offer solutions or advice on what to avoid. For me, Saurabh Mathur has been a great mentor, always providing clarity after our discussions. Thank you, Saurabh.</p><p>3. Make Time for Activities You Enjoy 🎨<br> We often get so absorbed in work that we neglect our hobbies and interests. These things I do: building piptrends.com, volunteering (I’m currently involved with PyCon), creating tech videos in Telugu, or learning something new. It’s important to engage in activities that bring you joy.</p><p>4. Prioritize Exercise, Sleep and Healthy Eating 🏃‍♂️💤🍏</p><p>5. Take Regular Breaks 🛑<br> While taking a trip can be refreshing, even small breaks can significantly impact your well-being. Avoid sitting in front of the computer all the time. Every hour or two, stand up, walk around for five minutes or enjoy the view of nature. Please don’t check your phone — it worsens the problem.</p><p>Bonus Tip: Focus on what you can control, not what you can’t. I know it’s a philosophical approach. But nowadays I am working on incorporating it. 🌱</p><p>This article was originally published on my blog — <a href="https://lulaguide.substack.com/p/my-goto-strategies-for-beating-burnout">https://lulaguide.substack.com/p/my-goto-strategies-for-beating-burnout</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=550c8d7b7c8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Halfway Through 2024 — Reflecting on Achievements and Adjustments]]></title>
            <link>https://medium.com/@ashok.tankala/halfway-through-2024-reflecting-on-achievements-and-adjustments-217ae444209b?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/217ae444209b</guid>
            <category><![CDATA[self-betterment]]></category>
            <category><![CDATA[stay-consistent]]></category>
            <category><![CDATA[yes-you-can]]></category>
            <category><![CDATA[unlock-your-potential]]></category>
            <category><![CDATA[new-year-resolution]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 27 May 2024 08:03:42 GMT</pubDate>
            <atom:updated>2024-05-27T08:03:42.011Z</atom:updated>
            <content:encoded><![CDATA[<h3>Halfway Through 2024 — Reflecting on Achievements and Adjustments</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPn1c7rQR3kMUFj-H8n6Vw.jpeg" /></figure><p>🎉 Excited to share some great news. I won 1 Silver medal and 2 Bronze medals at the Pan India Masters national event in the 35–39 years category. With almost half the year gone, it feels amazing to have achieved one of my biggest goals. Now, I’m reviewing my goals for the year.</p><p>Here are my New Year resolutions and progress so far:</p><p>1. Win a gold medal in a swimming competition<br> — 🥈 Won 1 Silver medal and 🥉 2 Bronze medals at the national level.</p><p>2. Clear one loan and save 50% of my retirement fund<br> — ✅ Cleared one loan and shifted focus to optimizing freedom by clearing my other loan instead of saving for retirement.</p><p>3. Understand the link between my travel and life choices<br> — 🌍 Had one trip and planned two more (one with family and one solo). Realized I love giving surprises more than just visiting places.</p><p>Setting challenging goals is important to push me out of my comfort zone. But it’s also okay if I don’t achieve them exactly as planned. What matters is the effort and progress.</p><p>I aimed for a gold medal at the district or state level but ended up winning Silver at the national level — an achievement I’m incredibly proud of, especially since I wasn’t an athlete in my younger years. This motivates me to keep striving for the next level.</p><p>Why am I sharing this?</p><p>1. To hold myself accountable.<br>2. To show that anything is possible if you are in the right direction. Whether you run, walk or crawl, you’ll reach your goal as long as you keep moving forward in the right direction.<br>3. To remind you that it’s okay to change goals if they no longer serve you. For example, I shifted my focus from saving for retirement to clearing loans for better mental peace. Follow what feels right for you.</p><p>Keep pushing and stay focused! 💪✨</p><p>This article was originally published on my blog — <a href="https://lulaguide.substack.com/p/halfway-through-2024-reflecting-on">https://lulaguide.substack.com/p/halfway-through-2024-reflecting-on</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=217ae444209b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Importance of Writing Test Cases and How to Get Started]]></title>
            <link>https://medium.com/@ashok.tankala/the-importance-of-writing-test-cases-and-how-to-get-started-048ffd83b323?source=rss-555eb7b60303------2</link>
            <guid isPermaLink="false">https://medium.com/p/048ffd83b323</guid>
            <category><![CDATA[tech-tips]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ashok Tankala]]></dc:creator>
            <pubDate>Mon, 20 May 2024 08:10:56 GMT</pubDate>
            <atom:updated>2024-05-20T08:10:56.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Automated tests don’t just save time, they let you be fearless." src="https://cdn-images-1.medium.com/max/1024/1*J_T8FFAS_J1zC4srXPkttw.png" /></figure><p>Many developers avoid writing test cases because they think it’s too hard or they’re just not used to it. But test cases actually keep your application behaving correctly over time. I know it’s a huge change but let me tell you how test cases can actually make your work easier and your code better.</p><h3>Why Write Test Cases?</h3><ol><li><strong>Find Bugs Early:</strong> Tests help you catch problems in your code before they become bigger issues. Sometimes to catch the problems in the code we didn’t touch it because the new code impacted it indirectly.</li><li><strong>Better Code Quality: </strong>Writing tests makes you think about how to write better code.</li><li><strong>Easier Changes:</strong> With tests, you can change your code confidently, knowing that tests will catch any mistakes.</li><li><strong>Code Documentation:</strong> Tests show how your code should work, which is helpful for new team members. You have 2 choices write so much documentation or write code comments where things are really complex and good test cases. Anyday most of the good developers(including me) who I know choose the 2nd option.</li><li><strong>Build Confidence:</strong> Knowing your code is tested gives you and your team confidence, speeding up development.</li></ol><h3>How to Start Writing Test Cases?</h3><p>The hardest part is getting started. Here’s how to make it easy:</p><ol><li><strong>Start Simple:</strong> Write small, simple tests first. For example, if you have a function that adds two numbers, write a test to check if it gives the correct result.</li><li><strong>Take Small Steps:</strong> Don’t try to write tests for everything at once. Add tests gradually, especially when you work on new features or fix bugs.</li><li><strong>Test What You Know:</strong> Begin with the parts of the code you understand best. This makes it less intimidating.</li><li><strong>Use Automation:</strong> Use tools that automatically run your tests and give feedback quickly. Examples include Jest for JavaScript, JUnit for Java or PyTest for Python.</li><li><strong>Work as a Team:</strong> Make test writing a team habit. Use code reviews to ensure tests are written and learn from each other.</li></ol><h3>How to Write Your First Test?</h3><ol><li><strong>Set Up Your Tools:</strong> Choose a testing tool that works with your programming language. For instance, use Jest for JavaScript or PyTest for Python.</li><li><strong>Write a Simple Test:</strong> Start with a basic function. May be from utility functions or write test cases for hitting an API and asserting the response.</li><li><strong>Expand Slowly:</strong> Once you’re comfortable, write more tests for different scenarios.</li><li><strong>Refactor Safely:</strong> With tests in place, you can change your code and use the tests to ensure nothing breaks.</li></ol><h3>Normal Complaints I hear &amp; My take</h3><ol><li><strong>No Time: </strong>It might feel like you don’t have time to write tests, but they save time by catching bugs early. Still not convinced then all the best for future time going to waste on fixing bugs.</li><li><strong>Too Complex:</strong> Tests might seem complicated at first, but starting with small, simple tests makes it easier.</li><li><strong>Team Resistance:</strong> It can be hard to get everyone on board. Show the benefits through reduced bugs and smoother updates.</li></ol><p>Writing test cases is very important for reliable software. Start small, focus on simple parts and make testing a regular part of your work. As you write more tests, you’ll feel more confident in your code, your team will work more smoothly and your software will be more reliable. Happy testing!</p><p>This article was originally published on my blog — <a href="https://lulaguide.substack.com/p/the-importance-of-writing-test-cases">https://lulaguide.substack.com/p/the-importance-of-writing-test-cases</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=048ffd83b323" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>