<?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[The Backend Tech - Medium]]></title>
        <description><![CDATA[Content on backend technologies focused on Java, Spring and everything backend - Medium]]></description>
        <link>https://medium.com/thebackendtech?source=rss----33614872e155---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>The Backend Tech - Medium</title>
            <link>https://medium.com/thebackendtech?source=rss----33614872e155---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:27:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/thebackendtech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Zero-Downtime Deployments in Node.js: A Practical Guide]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/zero-downtime-deployments-in-node-js-a-practical-guide-a1192a28eb3d?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/1536/1*taAHr1IPden90b1XjjoDcA.png" width="1536"></a></p><p class="medium-feed-snippet">If you&#x2019;ve ever pushed code to production and accidentally caused your app to go offline (yes, we&#x2019;ve all been there &#x1F440;), you know how&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/zero-downtime-deployments-in-node-js-a-practical-guide-a1192a28eb3d?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/zero-downtime-deployments-in-node-js-a-practical-guide-a1192a28eb3d?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/a1192a28eb3d</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[pm2]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:43:55 GMT</pubDate>
            <atom:updated>2025-11-18T07:43:45.899Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Securing Next.js Applications: Authentication, Authorization, and Beyond]]></title>
            <link>https://medium.com/thebackendtech/securing-next-js-applications-authentication-authorization-and-beyond-c4355efbbe82?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/c4355efbbe82</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Lucas Wade]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:42:40 GMT</pubDate>
            <atom:updated>2025-11-18T07:42:39.703Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Securing Next.js Applications" src="https://cdn-images-1.medium.com/max/1024/1*oio96lQqRFDZ2UT550Lt9Q.png" /></figure><p><a href="#151a">1. Next.js Authentication: Building the First Layer of Defense</a><br><a href="#8ded">2. Next.js Authorization: Controlling Access with Precision</a><br> <a href="#121b">Common Authorization Strategies in Next.js:</a><br> <a href="#3580">Example Middleware for Role-Based Authorization:</a><br><a href="#69a3">3. Protecting API Routes and Databases in Next.js</a><br> <a href="#7db0">Common API Threats:</a><br> <a href="#3168">Best Practices for Securing Next.js APIs:</a><br><a href="#558e">4. Next.js Security Best Practices: Hardening Your Application</a><br> <a href="#ee09">Key Security Best Practices for Next.js Applications:</a><br><a href="#a8cd">5. Emerging Trends: The Future of Securing Next.js Applications</a><br> <a href="#6196">Trends to Watch:</a><br><a href="#a9c9">Conclusion</a><br><a href="#f152">FAQs on Securing Next.js Applications</a></p><p>As businesses move toward scalable, cloud-native applications, security is no longer an afterthought — it’s the foundation of trust. Next.js, with its hybrid rendering capabilities and server-side features, powers thousands of production apps, from e-commerce platforms to enterprise dashboards. But with popularity comes risk: cyberattacks are growing at an alarming rate, with over 2,200 cyberattacks happening daily worldwide (Source: University of Maryland).</p><p>For developers, mastering Securing Next.js applications means understanding authentication, authorization, and security best practices that safeguard sensitive data and ensure compliance. In this guide, we’ll explore real-world tools, examples, and actionable strategies to strengthen your Next.js apps against modern threats.</p><h3><strong>1. Next.js Authentication: Building the First Layer of Defense</strong></h3><figure><img alt="Next.js Authentication" src="https://cdn-images-1.medium.com/max/360/1*7xTYZNfb_sRDOfV9ZIR5Fg.png" /></figure><p>Authentication is the gatekeeper — it verifies <em>who</em> a user is. In Next.js, authentication can be implemented using multiple strategies:</p><ul><li><strong>NextAuth.js</strong>: For Next.js projects, NextAuth.js provides a straightforward way to implement authentication with both third-party providers and custom credentials.</li><li><strong>JWT (JSON Web Tokens)</strong>: Ideal for stateless authentication in API-driven architectures.</li><li><strong>OAuth 2.0 &amp; OpenID Connect</strong>: Commonly used for enterprise-grade integrations (e.g., logging in with Microsoft Azure AD or Google Workspace).</li><li><strong>Passwordless Login</strong>: Using magic links or one-time codes via email or SMS.</li></ul><p><strong>Example Setup with NextAuth.js</strong>:</p><figure><img alt="Coding" src="https://cdn-images-1.medium.com/max/1024/1*GDHWAB1lYRjFpi8LwDc-1Q.png" /></figure><p><strong>Best Practice Tip</strong>: Always store JWTs in HTTP-only cookies instead of local Storage to reduce the risk of XSS attacks.</p><p>According to a 2024 OWASP report, 61% of web app vulnerabilities were related to authentication flaws — making Next.js authentication one of the most critical steps in securing applications.</p><h3><strong>2. Next.js Authorization: Controlling Access with Precision</strong></h3><figure><img alt="Next.js Authorization" src="https://cdn-images-1.medium.com/max/360/1*XlGtssru5c8BmJI5XY3Quw.png" /></figure><p>If authentication confirms <em>who</em> a user is, authorization defines <em>what they can do</em>. In Next.js, authorization ensures that different user roles — admin, editor, viewer — have the right permissions.</p><h4><strong>Common Authorization Strategies in Next.js:</strong></h4><ul><li><strong>Role-Based Access Control (RBAC):</strong> Assigns predefined roles like <em>Admin</em>, <em>Editor</em>, <em>User</em>.</li><li><strong>Attribute-Based Access Control (ABAC):</strong> Grants permissions based on user attributes (e.g., department = “HR”).</li><li><strong>Row-Level Security (RLS):</strong> Controls defined at the database itself, often leveraged in PostgreSQL setups.</li></ul><h4><strong>Example Middleware for Role-Based Authorization</strong>:</h4><figure><img alt="Coding" src="https://cdn-images-1.medium.com/max/1024/1*yLOUy0eGTrc0Mr5ZrdlXWQ.png" /></figure><p><strong>Best Practice Tip</strong>: Use server-side checks (API routes, middleware) instead of just client-side restrictions — otherwise, malicious users can bypass controls.</p><p>For growing teams, hiring specialists to design robust role systems can save significant effort — many enterprises <a href="https://www.onboardnow.ai/au/hire/next-js/">hire Next.js developers</a> specifically for implementing fine-grained authorization in complex systems.</p><h3><strong>3. Protecting API Routes and Databases in Next.js</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*gOU3a_mzYUJuIBUIqFm-TA.png" /></figure><p>Most modern Next.js applications rely on APIs and databases to serve dynamic content. API routes tend to be one of the most common attack surfaces.</p><h4><strong>Common API Threats:</strong></h4><ul><li>SQL Injection (still in OWASP Top 10)</li><li>Broken Access Control</li><li>Exposed API Keys</li><li>Rate-Limiting Attacks</li></ul><h4><strong>Best Practices for Securing Next.js APIs:</strong></h4><ol><li><strong>Use Middleware for Authentication:</strong> Protect /api/* routes with JWT or session checks.</li><li><strong>Enable Rate Limiting:</strong> Use libraries like express-rate-limit or cloud services (Cloudflare, AWS WAF).</li><li><strong>Sanitize User Input:</strong> Prevent injection attacks by using ORM libraries like Prisma or Sequelize.</li><li><strong>Secure Database Connections:</strong></li></ol><p>Always use environment variables for credentials.</p><p>Enable SSL connections for PostgreSQL, MySQL, or MongoDB.</p><p><strong>Stat:</strong> According to IBM’s 2024 Cost of a Data Breach report, the average cost of a breach caused by API vulnerabilities was $4.67M.</p><p><strong>Real-World Tool:</strong> Prisma ORM integrates seamlessly with Next.js, providing built-in query sanitization and type safety.</p><p>For businesses scaling rapidly, ensuring database security and API hardening becomes critical. This is one reason many businesses choose to <a href="https://www.onboardnow.ai/us/hire/next-js/">hire Next.js developers</a> who also bring strong backend security knowledge to the table.</p><h3><strong>4. Next.js Security Best Practices: Hardening Your Application</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*ntPm53WjzKyijje94vDq3Q.png" /></figure><p>Even the best authentication and authorization won’t protect against common web vulnerabilities if your app lacks broader security hardening.</p><h4><strong>Key Security Best Practices for Next.js Applications:</strong></h4><ul><li><strong>Use HTTPS Everywhere:</strong> Enforce SSL/TLS at the CDN or reverse proxy level.</li><li><strong>Secure Cookies:</strong> Always set HttpOnly, Secure, and SameSite attributes.</li><li><strong>Implement CSRF Protection:</strong> Use anti-CSRF tokens in sensitive requests.</li><li><strong>XSS Protection:</strong> Sanitize user inputs and leverage libraries like DOMPurify.</li><li><strong>CSP (Content Security Policy):</strong> Define which resources browsers are allowed to load.</li><li><strong>Dependency Audits:</strong> Run npm audit or yarn audit regularly.</li><li><strong>Secrets Management:</strong> Store API keys in services like AWS Secrets Manager or HashiCorp Vault.</li></ul><p><strong>Stat:</strong> According to Snyk’s 2024 State of Open Source Security report, 41% of Node.js applications had at least one critical vulnerability due to outdated packages.</p><p><strong>Tool Recommendation:</strong> <a href="https://www.npmjs.com/package/helmet?utm_source=chatgpt.com">Helmet</a> middleware for setting security headers in Next.js apps deployed on custom servers.</p><h3><strong>5. Emerging Trends: The Future of Securing Next.js Applications</strong></h3><figure><img alt="Emerging Trends in Next.js" src="https://cdn-images-1.medium.com/max/360/1*iNsU9Zjx5eY4QVvGRBafzA.png" /></figure><p>Security is evolving just as fast as frameworks. In 2025 and beyond, we’ll see Next.js security enhanced by AI-driven monitoring, edge computing, and zero-trust models.</p><h4><strong>Trends to Watch:</strong></h4><ul><li><strong>Edge Security with Vercel Edge Functions</strong>: Authentication and denial-of-service safeguards can be executed directly at the edge layer using Vercel Edge Functions.</li><li><strong>Zero Trust Architectures</strong>: “Never trust, always verify” applied to Next.js environments.</li><li><strong>AI-Powered Security Analytics</strong>: Using machine learning to detect unusual user patterns.</li><li><strong>Serverless Security Enhancements</strong>: AWS Lambda, Google Cloud Functions, and Azure Functions are improving runtime isolation.</li></ul><p>For developers, staying ahead of these trends is not optional. Understanding Next.js security best practices will be critical to building trustworthy apps in the cloud era.</p><h3><strong>Conclusion</strong></h3><p>Securing Next.js applications requires a layered approach — starting with authentication, enforcing precise authorization, protecting APIs and databases, applying security best practices, and staying updated with emerging trends.</p><p>A secure app not only prevents breaches but also builds user trust — the foundation of long-term business success.</p><h3><strong>FAQs on Securing Next.js Applications</strong></h3><p><strong>1. How do you secure authentication in Next.js?</strong> <br> Use libraries like NextAuth.js, secure cookies, and HTTPS. Always store JWTs in HTTP-only cookies.</p><p><strong>2. What is the best way to handle authorization in Next.js?</strong> <br> Implement role-based or attribute-based access controls using server-side middleware.</p><p><strong>3. How to protect API routes in Next.js?</strong> <br> Authenticate requests with JWT or sessions, enforce rate limiting, and sanitize inputs.</p><p><strong>4. Is NextAuth.js secure for production?</strong> <br> Yes, if configured properly with secure cookies, HTTPS, and secret keys.</p><p><strong>5. How to prevent CSRF and XSS attacks in Next.js?</strong> <br> Use anti-CSRF tokens, sanitize inputs with libraries like DOMPurify, and set a Content Security Policy.</p><p><strong>6. Does Next.js support zero-trust security models?</strong> <br> Yes — you can combine edge functions, serverless authentication, and fine-grained authorization to build a zero-trust Next.js environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4355efbbe82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebackendtech/securing-next-js-applications-authentication-authorization-and-beyond-c4355efbbe82">Securing Next.js Applications: Authentication, Authorization, and Beyond</a> was originally published in <a href="https://medium.com/thebackendtech">The Backend Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Notification System with BullMQ, Redis, and Node.js]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/how-to-build-a-notification-system-with-bullmq-redis-and-node-js-997fc704ea0b?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/1536/1*IPT3Byro_c7j_C9lf5VVCg.png" width="1536"></a></p><p class="medium-feed-snippet">Your step-by-step guide to building a scalable and reliable notification service.</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/how-to-build-a-notification-system-with-bullmq-redis-and-node-js-997fc704ea0b?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/how-to-build-a-notification-system-with-bullmq-redis-and-node-js-997fc704ea0b?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/997fc704ea0b</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[notification-system]]></category>
            <category><![CDATA[readers-club]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[bullmq]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:42:04 GMT</pubDate>
            <atom:updated>2025-11-18T07:42:03.679Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Build a Personal Dev Portfolio with GitHub Pages and Actions]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/how-to-build-a-personal-dev-portfolio-with-github-pages-and-actions-2318b3c20c26?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/1536/1*pMNZlK4n3LHSs0PvmY6Z0g.png" width="1536"></a></p><p class="medium-feed-snippet">Every developer needs a portfolio. It&#x2019;s your digital resume, your proof of work, and often the first impression potential employers or&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/how-to-build-a-personal-dev-portfolio-with-github-pages-and-actions-2318b3c20c26?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/how-to-build-a-personal-dev-portfolio-with-github-pages-and-actions-2318b3c20c26?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/2318b3c20c26</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[portfolio]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:40:37 GMT</pubDate>
            <atom:updated>2025-11-18T07:40:36.592Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why QA Needs AI More Than Ever in 2025]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/why-qa-needs-ai-more-than-ever-in-2025-645208448a9e?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/756/1*CBJsNeeihwMkfqieKkxz9A.png" width="756"></a></p><p class="medium-feed-snippet">Testing is one of those parts of software development that everyone knows is important&#x2026; but nobody loves doing.
&#xA0;You build features fast&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/why-qa-needs-ai-more-than-ever-in-2025-645208448a9e?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/why-qa-needs-ai-more-than-ever-in-2025-645208448a9e?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/645208448a9e</guid>
            <category><![CDATA[qa-testing]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ai-tools]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:40:03 GMT</pubDate>
            <atom:updated>2025-11-18T07:40:02.072Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Contribute to Open-Source Like a Pro (Beginner-Friendly)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/how-to-contribute-to-open-source-like-a-pro-beginner-friendly-734844541776?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/1536/1*6mVrrd0jWpde1-Ry8Nc5zA.png" width="1536"></a></p><p class="medium-feed-snippet">Open source is one of the best things about being a developer. It&#x2019;s a community-driven way to learn, collaborate, and give back. But let&#x2019;s&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/how-to-contribute-to-open-source-like-a-pro-beginner-friendly-734844541776?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/how-to-contribute-to-open-source-like-a-pro-beginner-friendly-734844541776?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/734844541776</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[contribution]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:38:30 GMT</pubDate>
            <atom:updated>2025-11-18T07:38:28.785Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How Small Dev Teams Can Compete Using Free & Open-Source Tech]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/how-small-dev-teams-can-compete-using-free-open-source-tech-4acc7fc159ed?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/1536/1*og7hyhm4sDURe522ZQuXHw.png" width="1536"></a></p><p class="medium-feed-snippet">Let&#x2019;s be honest&#x200A;&#x2014;&#x200A;being a small dev team in today&#x2019;s world can feel like competing in a Formula 1 race with a used bike. Big companies have&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/how-small-dev-teams-can-compete-using-free-open-source-tech-4acc7fc159ed?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/how-small-dev-teams-can-compete-using-free-open-source-tech-4acc7fc159ed?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/4acc7fc159ed</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[free-tools]]></category>
            <category><![CDATA[framework]]></category>
            <dc:creator><![CDATA[Somendradev]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:36:47 GMT</pubDate>
            <atom:updated>2025-11-18T07:36:45.974Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How To Build Large Scale Data Pipelines Using Meta-data Driven Approach In Azure Data Factory?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/thebackendtech/how-does-build-large-scale-data-pipelines-using-meta-data-driven-approach-in-azure-data-factory-f3f6193acad0?source=rss----33614872e155---4"><img src="https://cdn-images-1.medium.com/max/600/1*mlR-v_zo0jQf2KeRF-FpVw.png" width="600"></a></p><p class="medium-feed-snippet">Hey Everyone!</p><p class="medium-feed-link"><a href="https://medium.com/thebackendtech/how-does-build-large-scale-data-pipelines-using-meta-data-driven-approach-in-azure-data-factory-f3f6193acad0?source=rss----33614872e155---4">Continue reading on The Backend Tech »</a></p></div>]]></description>
            <link>https://medium.com/thebackendtech/how-does-build-large-scale-data-pipelines-using-meta-data-driven-approach-in-azure-data-factory-f3f6193acad0?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/f3f6193acad0</guid>
            <category><![CDATA[azure-data-factory]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[azure-data-engineer]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Manan Choudhary]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 07:36:01 GMT</pubDate>
            <atom:updated>2026-04-02T13:16:51.284Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Load Balancers — A technical deep dive]]></title>
            <link>https://medium.com/thebackendtech/understanding-load-balancers-a-technical-deep-dive-ff8d73f6d8df?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/ff8d73f6d8df</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Somnath Musib]]></dc:creator>
            <pubDate>Fri, 29 Aug 2025 11:35:05 GMT</pubDate>
            <atom:updated>2025-08-29T12:00:55.029Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Load Balancers — A technical deep dive</h3><h4>Architecting Scalable and Resilient Systems Through Strategic Load Distribution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LVairarUs-Xs9tWg" /><figcaption>Image Courtesy: <a href="https://unsplash.com/photos/three-traffic-lights-hanging-from-a-wire-with-a-blue-sky-in-the-background-Y-W7GoXLJgw">https://unsplash.com/photos/three-traffic-lights-hanging-from-a-wire-with-a-blue-sky-in-the-background-Y-W7GoXLJgw</a></figcaption></figure><p>A load balancer distributes incoming network traffic across multiple servers to ensure that no single server is overloaded, and the traffic is uniformly distributed. This improves the application availability, scalability, performance and the reliability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*V-SANWM4p3vH2VCA4j-pqQ.png" /></figure><h3><strong>Types of load balancer</strong></h3><h4><strong><em>By OSI Layer: Layer 4 &amp; Layer 7</em></strong></h4><p>A load balancer can operate at transport layer (Layer 4) or at the application layer (Layer 7).</p><p>A layer 4 load balancer routes the request based on IP address and port. This load balancers are fast and works with TCP or UDP protocols. An example of layer 4 load balancer is AWS Network Load Balancer (NLB).</p><p>A layer 7 load balancer operates on the application layer and routes the incoming request based on the content, such as HTTP headers, URLs, cookies, and so on. It can make more intelligent routing decisions as it operates on the application layer, and it can also modify the HTTP request and the response. This load balancer performs slower than the layer 4 load balancer due to the HTTP processing overhead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*gVEKboK2QHjjI9gPR1URRg.png" /><figcaption>Layer 7 Load Balancer</figcaption></figure><h4><strong><em>By Deployment: Hardware &amp; software load balancer</em></strong></h4><p>We can also categorize the load balancers based on hardware or software level load balancers. A hardware load balancer is a physical appliance that is purpose-built for load balancing. An example of hardware load balancer is F5 BIG-IP (https://www.f5.com/products/big-ip).</p><p>Software load balancer, as the name indicates is implemented through the software. Examples of software load balancers are Ngnix, Apache HTTP Server (using mod_proxy_balancer module), HAProxy etc.</p><h4><strong><em>By Architecture: Reverse &amp; Forward Proxy</em></strong></h4><p>Based on how the load balancer operates, it can be a reverse proxy or a forward proxy. It is called as proxy as it hides the client and proxy the request on their behalf.</p><p>A reverse proxy load balancer sits between client and servers and hides the backend server details to the client. Client always interacts with the load balancer. This type is the primary usage of the load balancers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*tKnPklq5r39ePo5lJAkqmQ.png" /><figcaption>Reverse proxy</figcaption></figure><p>A forward proxy load balancer sits between client and the internet/web server and hides the actual client details to the internet/web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*B-JVFe2iBaSBEcwOkrgRaQ.png" /><figcaption>Forward Proxy</figcaption></figure><h3>Load Balancer Algorithms</h3><p>Load balancer algorithms can be categorized into two types — static and dynamic. Let’s understand the static types:</p><h4>Round Robin</h4><p>In round robin algorithm, the load balancer routes the requests in a round robin fashion to the backend servers.</p><p>With this algorithm, the load balancer maintains a circular list of available servers and an index pointer that advances with each request. When a request arrives, the load balancer selects the server at the current index position, forwards the request, and increments the index to the next server in the list. Once the index reaches the end of the server list, it wraps around to the beginning, ensuring equal distribution across all available servers. This stateful approach requires the load balancer to track both the server pool and the current position, making it simple to implement but requiring careful handling during server pool changes and load balancer restarts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCwnQOUUtbEr7YOfuvr1Hg.png" /><figcaption>Figure Round robin load balancing</figcaption></figure><p>In the above diagram, the load balancer maintains the list of server pool [s0, s1 and s2] and an index initialized with 0. For the first request, it applies 3%0=0 and routes to the first server. It then increments the index by 1. For the next request, it applies 1%3=1 and the request is routed to server 2.</p><h4>Weighted Round-Robin</h4><p>This algorithm is useful when the servers are of varied capacity. I.e. some servers have more processing power and capacity while some have less processing capacity. Thus, instead of treating all servers equally, weighted round-robin assigns a weight value to each server based on its relative capacity and distributes requests proportionally to these weights. For example, if Server A has weight 3, Server B has weight 2, and Server C has weight 1, then out of every 6 requests, Server A receives 3 requests, Server B receives 2 requests, and Server C receives 1 request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOs6kPBKes9LPplCSPJfXw.png" /><figcaption>Figure Weighted round-robin</figcaption></figure><h4>IP Hash</h4><p>IP Hash algorithm uses the client’s IP address as input to a hash function to determine which backend server should handle the request.</p><p>The load balancer calculates a hash value from the client’s IP address and uses modulo operation with the number of available servers to select the target server. This ensures that requests from the same client IP will consistently be routed to the same backend server. This provides implicit session affinity without any server-side session storage or cookie management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_0h4pClRh628F1zPNDADQ.png" /><figcaption>Figure: IP Hash</figcaption></figure><p>In the above example, a client with IP address 192.168.1.100 requests load balancer. It then applies the hash on the IP address and generates a hash value and applies modulo operation to find the server index. The request is forwarded to the server, in this case server 0. All subsequent requests are also forwarded to the same server.</p><p>Most enterprise grade load balancers use <a href="https://en.wikipedia.org/wiki/Consistent_hashing">consistent hashing</a> or ring-based approaches to minimize server reassignment when the backend server pool changes.</p><p>Next, lets discuss the dynamic types:</p><h4>Least Connections</h4><p>The Least Connections algorithm routes incoming requests to the backend server that currently has the fewest active connections.</p><p>This approach provides better load distribution than round-robin <strong>when request processing times vary significantly</strong>, as it automatically adapts to server performance differences. The load balancer maintains a real-time count of active connections for each server, incrementing the count when forwarding a request and decrementing it when the connection closes or the response is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*6LUFkjhTIEVaw6w9Qglvww.png" /><figcaption>Figure: Least Connections</figcaption></figure><h4>Weighted Least Connections</h4><p>Weighted Least Connections combines the least connections algorithm with the weighted round-robin. Each server is assigned a weight based on its capacity. The algorithm routes requests to the server with the lowest ratio of current connections to the assigned weight. This approach ensures that high-capacity servers can handle proportionally more concurrent connections while still adapting to real-time load variations and varying request processing times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYApqPEmlx_8X6PEEvGoSg.png" /><figcaption>Figure: Weighted Least Connections</figcaption></figure><h3>Conclusion</h3><p>In this article, we explored the concept of load balancing. We discussed the different types of load balancers, including Layer 4 (transport layer) and Layer 7 (application layer). Additionally, we examined various load balancing algorithms, such as Round Robin, Weighted Round Robin, IP Hash, Least Connections, Weighted Least Connections with detailed explanations on how each algorithm distributes traffic.</p><p><em>If you like this article, you can subscribe to my newsletter at </em><a href="https://musibs.substack.com/"><em>https://musibs.substack.com/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff8d73f6d8df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebackendtech/understanding-load-balancers-a-technical-deep-dive-ff8d73f6d8df">Understanding Load Balancers — A technical deep dive</a> was originally published in <a href="https://medium.com/thebackendtech">The Backend Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Java Concurrency: Advanced Executors]]></title>
            <link>https://medium.com/thebackendtech/mastering-java-concurrency-advanced-executors-27de97cbc4bd?source=rss----33614872e155---4</link>
            <guid isPermaLink="false">https://medium.com/p/27de97cbc4bd</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Somnath Musib]]></dc:creator>
            <pubDate>Sat, 02 Nov 2024 21:09:50 GMT</pubDate>
            <atom:updated>2024-11-02T21:09:49.972Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Guide to Using ScheduledExecutorService, ThreadFactory, and ThreadPoolExecutor for Efficient Task Execution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ifIxdd12yeuv8OWH" /><figcaption><a href="https://unsplash.com/s/photos/jyv%C3%A4skyl%C3%A4%2C-finland">Jyväskylä, Finland</a>, Image Courtesy: Unsplash, <a href="https://unsplash.com/@tommytop">Tommaso Fornoni</a></figcaption></figure><p>In the <a href="https://medium.com/thebackendtech/mastering-java-concurrency-core-concepts-and-essentials-6e5291cd324a">previous article</a>, we talked about some of the core interfaces of the java.util.concurrentpackage. This article will dive into more advanced constructs — <em>ScheduledExecutorService</em>, <em>ThreadFactory</em>, and <em>ThreadPoolExecutor</em>.</p><h4>ScheduledExecutorService</h4><p>This special type of <strong>Executor can schedule tasks to run after a given delay or to execute periodically</strong>. This interface has the following methods:</p><pre><br>public ScheduledFuture&lt;?&gt; schedule(Runnable command,<br>                                   long delay, <br>                                   TimeUnit unit);<br><br>public &lt;V&gt; ScheduledFuture&lt;V&gt; schedule(Callable&lt;V&gt; callable,<br>                                       long delay, <br>                                       TimeUnit unit);<br><br>public ScheduledFuture&lt;?&gt; scheduleAtFixedRate(Runnable command,<br>                                              long initialDelay,<br>                                              long period,<br>                                              TimeUnit unit);<br><br>public ScheduledFuture&lt;?&gt; scheduleWithFixedDelay(Runnable command,<br>                                                 long initialDelay,<br>                                                 long delay,<br>                                                 TimeUnit unit);<br></pre><p>The <em>schedule(..) </em>method schedules a <em>Runnable </em>or <em>Callable </em>to execute after the supplied delay. This is for one-off execution.</p><p>The following example demonstrates the use of <em>ScheduledExecutorService </em>with a <strong>Runnable </strong>implementation with a delay of 1 second.</p><pre>ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);<br>scheduledExecutorService.schedule(() -&gt; System.out.println(&quot;Executed by &quot;+Thread.currentThread().getName()), <br>                                  1, <br>                                  TimeUnit.SECONDS);</pre><p>The following example demonstrates the use of <em>ScheduledExecutorService </em>with a <strong>Callable</strong> implementation with a delay of 1 second.</p><pre>// 1) Create an instance of scheduledExecutorService. In this example, we <br>// are creating a ScheduledThreadPool with 1 thread.<br>ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);<br><br>// 2) Submit an instance of Callable with a delay of 10 seconds.<br>ScheduledFuture&lt;Integer&gt; callableSum = scheduledExecutorService.schedule(() -&gt; {<br>    return IntStream.rangeClosed(1,10).sum();<br>}, 10, TimeUnit.SECONDS);<br><br>System.out.println(&quot;Execution to callableSum is &quot;+(callableSum.isDone() ? &quot;done&quot; : &quot;not done &quot;) +&quot;and has delay of &quot;+callableSum.getDelay(TimeUnit.SECONDS) +&quot; seconds.&quot;);<br>TimeUnit.SECONDS.sleep(3);<br>System.out.println(&quot;Execution to callableSum is &quot;+(callableSum.isDone() ? &quot;done&quot; : &quot;not done &quot;) +&quot;and has delay of &quot;+callableSum.getDelay(TimeUnit.SECONDS) +&quot; seconds.&quot;);<br>int result = callableSum.get();<br>System.out.println(&quot;Execution to callableSum is &quot;+(callableSum.isDone() ? &quot;done &quot; : &quot;not done &quot;) +&quot;and result is &quot;+result);<br><br>scheduledExecutorService.shutdown();</pre><p>The return type of <em>schedule(..)</em> method of the <em>Callable </em>variant is <em>ScheduledFuture</em> which is a special type of <em>Future. </em>The <em>ScheduledFuture </em>adds the capabilities of the <em>Delayed</em> interface which lets us inspect the pending delay of the submitted job.</p><p>The following is the outcome of the above code snippet:</p><pre>Execution to callableSum is not done and has delay of 9 seconds.<br>Execution to callableSum is not done and has delay of 6 seconds.<br>Execution to callableSum is doneand result is 55</pre><p>The <em>scheduleAtFixedRate(..)</em> and <em>scheduleAtFixedDelay(..)</em> lets us schedule tasks that execute periodically. The main difference between these two methods lies in how they execute the task.</p><p>The scheduleAtFixedRate(..) lets us submit a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after <em>initialDelay </em>then <em>initialDelay + period</em>, then <em>initialDelay + 2 * period</em> and so on.</p><p>Let us see the use of <em>scheduleAtFixedRate(..)</em> in the following example:</p><pre>scheduledExecutorService.scheduleAtFixedRate(() -&gt; System.out.println(&quot;Executing at &quot;+ LocalDateTime.now()), <br>                                              0, <br>                                              3, <br>                                              TimeUnit.SECONDS);</pre><p>In the above code snippet, we are scheduling a task that starts with no initial delay and executes at a rate of 3 seconds. i.e.</p><p>Start at 0 and execute, then run after 3 seconds from the last start time (0+ 1 *3 seconds), next run after 0 + 2*3 seconds and so on.</p><p>The following is the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*t4oGtrMey3ReGV6iQKm3RQ.png" /><figcaption><em>scheduleAtFixedRate(..) execution</em></figcaption></figure><p>The <em>scheduleAtFixedDelay(..) </em>lets us create a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.</p><p>The following code snippet demonstrates the use of <em>scheduleAtFixedDelay(..)</em></p><pre>scheduledExecutorService.scheduleWithFixedDelay(() -&gt; {<br>            System.out.println(&quot;Executing at &quot;+ LocalTime.now());<br>            try {<br>                TimeUnit.SECONDS.sleep(3);<br>            } catch (InterruptedException e) {<br>                throw new RuntimeException(e);<br>            }<br>        }, 0, 3, TimeUnit.SECONDS);</pre><p>In the above example, we are executing a task with no initial delay and a fixed delay of 3 seconds. The task takes 3 seconds to finish. The following is the outcome:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLH6-cO30iB9ffF6pLps8A.png" /><figcaption><em>scheduleAtFixedDelay(..) execution</em></figcaption></figure><blockquote>A detailed discussion on the difference between scheduleWithFixedRate and scheduleWithFixedDelay could be found at <a href="https://stackoverflow.com/questions/24649842/scheduleatfixedrate-vs-schedulewithfixeddelay">this StackOverflow</a> link.</blockquote><h4>ThreadFactory</h4><p><strong>A ThreadFactory lets us create a new thread and customize the thread behaviour</strong>. We can provide custom thread name, priority, daemon thread etc. Using this interface removes the need for direct invocation of <em>new Thread().</em></p><p>Let us demonstrate the use of <em>ThreadFactory</em>. We’ll first define our Thread class — <em>AppThread </em>and then define a new <em>ThreadFactory </em>implementation <em>AppThreadFactory </em>that creates new threads.</p><pre>public class AppThread extends Thread {<br><br>   private static final String POOL_DELIMITER = &quot;-&quot;; <br><br>   /**<br>    * Application thread<br>    * <br>    * @param runnable, tasks to be processed<br>    * @param pool, name of the pool<br>    * @param id, Identifier for the thread<br>    */<br>   public AppThread(ThreadGroup group, Runnable runnable, String pool, int id) {<br>      super(group, runnable, String.format(&quot;%s%s%d&quot;, pool+&quot;-thread&quot;, POOL_DELIMITER, id));<br>   }<br><br>}</pre><p>In the above code snippet, we are extending the <em>Thread </em>class to define the custom thread pool name.</p><pre>public class AppThreadFactory implements ThreadFactory{<br><br> private String poolName;<br> private ThreadGroup group;<br><br> private AtomicInteger atomicInteger = new AtomicInteger();<br> <br> public AppThreadFactory(String poolName) {<br>    this.poolName = poolName;<br>    group = Thread.currentThread().getThreadGroup();<br> }<br> <br> @Override<br> public Thread newThread(Runnable runnable) {<br>    Thread appThread = new AppThread(group, runnable, poolName, atomicInteger.incrementAndGet());<br>    if(appThread.isDaemon()) {<br>       appThread.setDaemon(false);<br>    }<br>    if(appThread.getPriority() != Thread.NORM_PRIORITY) {<br>       appThread.setPriority(Thread.NORM_PRIORITY);<br>    }<br>    return appThread;<br>   }<br>}</pre><p>In the above example, we define a custom implementation of the ThreadFactory interface. The <em>AppThreadFactory </em>creates new instances of the <em>AppThread</em> class. It customizes the Daemon property and priority of the generated threads.</p><p>Lastly, let us define an ExecutorService with this <em>AppThreadFactory </em>implementation:</p><pre> ExecutorService executorService = Executors.newFixedThreadPool(2, new AppThreadFactory(&quot;medium-demo&quot;));<br> executorService.execute(() -&gt; {<br>     IntStream.rangeClosed(1,4).forEach((i) -&gt; System.out.println(&quot;Executed by &quot;+Thread.currentThread().getName()));<br> });</pre><p>In the above snippet, we are creating a FixedThreadPool with 2 threads and using the <em>AppThreadFactory</em> implementation. Next, we submit a task to print a few statements to view the thread name.</p><pre>Executed by medium-demo-thread-1<br>Executed by medium-demo-thread-1<br>Executed by medium-demo-thread-1<br>Executed by medium-demo-thread-1</pre><p>The output prints the thread name as customized in the <em>AppThreadFactory.</em></p><h4>ThreadPoolExecutor</h4><p><strong>ThreadPoolExecutor is the thread pool implementation provided in Java.</strong></p><p>Though this class provides the full implementation for a thread pool, programmers often use more specific types of thread pools e.g. <em>FixedThreadPool</em>, <em>CachedThreadPool</em>, <em>SingleThreadExeutor</em>, <em>WorkStealingPool </em>etc, based on the task processing needs. For instance, a <em>FixedThreadPool </em>provides a fixed set of threads for task execution with a <em>LinkedBlockingQueue </em>as a backing queue for task queuing if tasks can not be picked up for immediate processing. This implementation is suitable for good resource optimization.</p><p>Before proceeding further, let us understand how a thread pool internally works. A thread pool executor has the following properties that can be customized:</p><ol><li>Core Pool Size</li><li>Maximum Pool Size</li><li>Keep Alive Time</li><li>A Queue</li><li>A Thread Factory</li><li>Rejection Execution Handler</li></ol><p><strong>Core Pool Size: </strong>This is the minimum number of threads that should be always available in the pool. This is applicable even if there are no active tasks available in the pool for processing. In the event of an abnormal termination of a core pool thread, Java ensures a new thread is created and the core pool size is maintained. However, core pool size threads can be terminated if the <em>allowCoreThreadTimeOut </em>flag is set to true. In this case, core pool threads will be terminated once <em>keepAliveTime </em>expires. The thread pool will have no thread if the pool is inactive and the <em>keepAliveTime </em>expires for all core pool threads.</p><p><strong>Maximum Pool Size: </strong>This is the maximum number of threads that a pool can have and can not go beyond this value.</p><p><strong>Queue: </strong>A queue is used internally to hold the additional tasks once all core pool threads are occupied and not available for new tasks. It is important to note that a new thread is only created if fewer threads are running than the configured number of core poll threads and the job is submitted for processing rather than queuing.</p><p><strong>Thread Factory: </strong>A thread factory is used to create new threads in the thread pool.</p><p><strong>Rejection Execution Handler: </strong>This handler is used to decide when the thread pool is not able to accept new tasks due to various reasons. This includes the max pool size limit that has been reached or the backing queue is full. There are different policies on how to handle tasks that can not be processed by the pool.</p><p>The following example shows the usage of a ThreadPoolExecutor:</p><pre><br> private static final int CORE_POOL_SIZE = 1;<br> private static final int MAX_POOL_SIZE = 2;<br> private static final int KEEP_ALIVE_TIME = 10;<br><br>/** Create a new thread pool executor<br>   *  The minimum number of threads is 1<br>   *  The maximum number of threads is 2<br>   *  Keep alive time for idle thread is 10 seconds<br>   *  The backing queue implementation is an ArrayBlockingQueue with capacity 2<br>   *  The custom thread factory AppThreadFactory is used<br>   *  The RejectedExecutionHandler is CallerRunsPolicy<br>   */<br>  ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,<br>                  MAX_POOL_SIZE,<br>                  KEEP_ALIVE_TIME,<br>                  TimeUnit.SECONDS,<br>                  new ArrayBlockingQueue&lt;&gt;(1),<br>                  new AppThreadFactory(&quot;medium-demo&quot;),<br>                  new ThreadPoolExecutor.CallerRunsPolicy()<br>                  );<br>  // Prints the executing thread&#39;s name - medium-demo-thread-1<br>  threadPoolExecutor.execute(() -&gt; System.out.println(Thread.currentThread().getName()));</pre><p>Let us explore the use of queue and CallerRunsPolicy a bit more:</p><pre><br> private static final int CORE_POOL_SIZE = 1;<br> private static final int MAX_POOL_SIZE = 2;<br> private static final int KEEP_ALIVE_TIME = 10;<br>    <br> public static void main(String[] args) throws InterruptedException {<br><br><br>    /** Create a new thread pool executor<br>     *  The minimum number of threads is 1<br>     *  The maximum number of threads is 2<br>     *  Keep alive time for idle thread is 10 seconds<br>     *  The backing queue implementation is an ArrayBlockingQueue with capacity 2<br>     *  The custom thread factory AppThreadFactory is used<br>     *  The RejectedExecutionHandler is CallerRunsPolicy<br>     */<br>    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,<br>                    MAX_POOL_SIZE,<br>                    KEEP_ALIVE_TIME,<br>                    TimeUnit.SECONDS,<br>                    new ArrayBlockingQueue&lt;&gt;(1),<br>                    new AppThreadFactory(&quot;medium-demo&quot;),<br>                    new ThreadPoolExecutor.CallerRunsPolicy()<br>                    );<br>    // Prints the executing thread&#39;s name - medium-demo-thread-1<br>    threadPoolExecutor.execute(() -&gt; System.out.println(Thread.currentThread().getName()+&quot; executed this task&quot;));<br>  <br>  <br>    // Make the thread sleep so that it is not available for processing<br>    threadPoolExecutor.execute(() -&gt; {<br>     try {<br>      Thread.sleep(500000);<br>     }<br>     catch(InterruptedException ie) {<br>      //<br>     }<br>    });<br>  <br>    // Prints the executing thread&#39;s name - This task is queued.<br>    threadPoolExecutor.execute(() -&gt; System.out.println(Thread.currentThread().getName()+&quot; executed this task&quot;));<br>  <br>    TimeUnit.SECONDS.sleep(2);<br>  <br>    // Remaining capacity is 0 as there is a task already queues. Since the queue size is 1. The queue is now full.<br>    System.out.println(&quot;Remaining queue capacity: &quot;+threadPoolExecutor.getQueue().remainingCapacity());<br>  <br>    /**<br>     *  A new thread is created and put to sleep. At this stage, the max thread pool limit is reached.<br>     *  No new threads can be created.<br>     */<br>    threadPoolExecutor.execute(() -&gt; {<br>     try {<br>      System.out.println(Thread.currentThread().getName() + &quot; is created and going to sleep&quot;);<br>      Thread.sleep(500000);<br>     }<br>     catch (InterruptedException ie) {}<br>    });<br>  <br>    /**<br>     *  This task is executed by the main thread due to CallerRunPolicy.<br>     *  Since both the threads of the pool is occupied and the queue is also full,<br>     *  based on the CallerRunPolicy, Main thread executed the new tasks.<br>     */<br>    threadPoolExecutor.execute(() -&gt; System.out.println(Thread.currentThread().getName()+&quot; thread executed this task&quot;));<br>    threadPoolExecutor.execute(() -&gt; System.out.println(Thread.currentThread().getName()+&quot; thread executed this task&quot;));<br>    threadPoolExecutor.shutdownNow();<br>}</pre><p>The following is the output (Output will vary due to thread scheduling):</p><pre>medium-demo-thread-1 executed this task<br>Remaining queue capacity: 0<br>medium-demo-thread-2 is created and going to sleep<br>main thread executed this task<br>main thread executed this task</pre><h4>Conclusion</h4><p>This article provides an overview of the <em>ScheduledExecutorService, ThreadFactory, </em>and <em>ThreadPoolExecutor.</em></p><p>A <em>ScheduledExecutorService </em>lets us schedule tasks. This scheduling can be one-time or recurring. The schedule, scheduleAtFixedRate, and scheduleAtFixedDelay are the important methods.</p><p>A ThreadFactory lets us create custom threads and removes the need for direct instantiation of the <em>Thread </em>class.</p><p>A <em>ThreadPoolExecutor </em>is a concrete implementation of a thread pool in Java. It provides a rich configuration set to customize the pool properties and their behaviour.</p><p>The source code for this article is available in the following <a href="https://github.com/musibs/Java-Concurrency">GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27de97cbc4bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebackendtech/mastering-java-concurrency-advanced-executors-27de97cbc4bd">Mastering Java Concurrency: Advanced Executors</a> was originally published in <a href="https://medium.com/thebackendtech">The Backend Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>