<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AddWeb Solution Pvt Ltd</title>
    <description>The latest articles on DEV Community by AddWeb Solution Pvt Ltd (addwebsolutionpvtltd).</description>
    <link>https://dev.to/addwebsolutionpvtltd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F11063%2F0b7a4ce4-43ab-4718-abd0-1d314bc88f99.png</url>
      <title>DEV Community: AddWeb Solution Pvt Ltd</title>
      <link>https://dev.to/addwebsolutionpvtltd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/addwebsolutionpvtltd"/>
    <language>en</language>
    <item>
      <title>REST vs GraphQL vs gRPC: Choosing the Right API Architecture</title>
      <dc:creator>Lakashya Upadhyay</dc:creator>
      <pubDate>Wed, 22 Jul 2026 12:28:00 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/rest-vs-graphql-vs-grpc-choosing-the-right-api-architecture-fa4</link>
      <guid>https://dev.to/addwebsolutionpvtltd/rest-vs-graphql-vs-grpc-choosing-the-right-api-architecture-fa4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“The best API is the one that fits your use case, not the one that’s trending.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Practical Guide to Choosing Between REST, GraphQL, and gRPC for Modern Applications&lt;/p&gt;

&lt;p&gt;In modern application development, your API architecture shapes how your frontend and backend communicate, how easy it is to scale, and how much control you have over data flow. REST, GraphQL, and gRPC are the three dominant API styles in 2026, but they solve very different problems.&lt;/p&gt;

&lt;p&gt;This guide explains the most important differences between these API architectures, where each one shines, and how to avoid common mistakes when choosing the right tool for your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;REST is the standard choice for public, browser-friendly APIs and simple CRUD systems. GraphQL gives clients flexible, fine-grained data fetching, ideal for complex UIs. gRPC excels in high-performance, internal microservices using binary protocols. Each API style has distinct strengths for performance, tooling, and developer experience. Choosing the right architecture depends on your frontend needs, team skills, and scalability requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why This Matters&lt;/li&gt;
&lt;li&gt;Choosing Based on the Wrong Criterion&lt;/li&gt;
&lt;li&gt;REST, GraphQL, and gRPC Are Not the Same&lt;/li&gt;
&lt;li&gt;Data Fetching and Payload Efficiency&lt;/li&gt;
&lt;li&gt;Performance and Network Usage&lt;/li&gt;
&lt;li&gt;Caching and Browser Compatibility&lt;/li&gt;
&lt;li&gt;Streaming and Real-Time Needs&lt;/li&gt;
&lt;li&gt;Tooling and Ecosystem&lt;/li&gt;
&lt;li&gt;Team Preferences and Learning Curve&lt;/li&gt;
&lt;li&gt;Scaling Considerations&lt;/li&gt;
&lt;li&gt;Hybrid API Architectures&lt;/li&gt;
&lt;li&gt;Frequently Asked Questions (FAQs)&lt;/li&gt;
&lt;li&gt;Interesting Facts &amp;amp; Stats&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Choosing an API architecture is not just about syntax. It affects how efficiently data moves between systems, how easy it is to maintain your codebase, and how well your application scales as traffic grows.&lt;/p&gt;

&lt;p&gt;REST is the most widely used style and is deeply integrated with HTTP, making it simple and broadly compatible. GraphQL focuses on client-driven queries, letting frontends request exactly what they need. gRPC is optimized for speed and efficiency, using binary protocols and HTTP/2 for internal communication.&lt;/p&gt;

&lt;p&gt;This matters especially in public-facing APIs, mobile and web applications with complex UIs, high-throughput microservices, and systems with strict latency or bandwidth constraints. A poor API choice can lead to over-fetching, slow responses, and harder maintenance. A good choice helps your team move faster without sacrificing performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing Based on the Wrong Criterion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Don’t pick an API style because it’s popular.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A common mistake is choosing REST, GraphQL, or gRPC based only on hype, tutorials, or what another team uses. That can create problems when your project’s needs differ from the original use case.&lt;/p&gt;

&lt;p&gt;How to think about it:&lt;br&gt;
Choose REST if you want a simple, standard API with broad tooling support. Choose GraphQL if you want flexible queries and fewer round trips for complex UIs. Choose gRPC if you need low-latency, high-throughput communication between services.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Evaluate your client needs. Consider how much data control your frontend requires. Think about performance and infrastructure constraints. Match the API style to your project’s scale and team experience.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Better alignment with your use case. Fewer rewrites later. Cleaner system architecture.&lt;/p&gt;
&lt;h2&gt;
  
  
  REST, GraphQL, and gRPC Are Not the Same
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Similar goals do not mean the same workflow.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;REST, GraphQL, and gRPC all help systems talk to each other, but their philosophies and mechanics differ significantly. REST is resource-based and uses HTTP methods, GraphQL is query-based with a single endpoint, and gRPC is RPC-based with strongly typed contracts and binary serialization.&lt;/p&gt;

&lt;p&gt;Example difference:&lt;/p&gt;

&lt;p&gt;REST style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /users/123
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GraphQL style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="err"&gt;graphql&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;gRPC style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="n"&gt;text&lt;/span&gt;
&lt;span class="kd"&gt;service&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;rpc&lt;/span&gt; &lt;span class="n"&gt;GetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GetUserRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How to fix it&lt;br&gt;
Understand the mental model before adopting any style. Use REST for simple resources and standard HTTP patterns. Use GraphQL when you need flexible, client-driven queries. Use gRPC for high-performance, contract-based service communication.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Cleaner code decisions. Fewer architectural surprises. More predictable development flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Fetching and Payload Efficiency
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Fetching the right data at the right size matters.”&lt;br&gt;
One of the biggest differences is how each API handles data fetching. REST often returns fixed structures, which can lead to over-fetching or under-fetching. GraphQL lets clients request exactly what they need, reducing payload size for complex UIs. gRPC uses compact binary formats, minimizing payload size for internal services.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Use REST for standard resource endpoints where fixed responses are acceptable. Use GraphQL when your frontend needs flexible, nested data without multiple calls. Use gRPC when you want efficient, strongly typed data transfer between services.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Reduced bandwidth usage. Fewer round trips. Better performance for mobile and internal systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance and Network Usage
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Performance is more than just raw speed.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each API style has different performance characteristics. REST is simple and cacheable but can be chatty for complex data needs. GraphQL reduces round trips but can introduce query complexity and latency under heavy load. gRPC is optimized for speed with binary payloads and HTTP/2 multiplexing, making it ideal for high-throughput microservices.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Profile your real API calls early. Avoid over-fetching in REST by designing focused endpoints. Control GraphQL query depth and complexity. Use gRPC for internal, performance-critical communication.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Faster response times. Lower network overhead. More predictable performance at scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caching and Browser Compatibility
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Not all APIs play well with browsers and caches.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;REST is naturally compatible with HTTP caching and works seamlessly in browsers. GraphQL can use caching but requires more custom setup since it does not follow standard HTTP caching patterns. gRPC does not run natively in browsers and requires gRPC-Web or proxies, making it less suitable for direct frontend use.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Use REST for public APIs and browser-based clients. Use GraphQL for complex UIs where flexible queries matter more than simple caching. Use gRPC for internal service-to-service communication, not direct browser access.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Better caching strategies. Simpler client integration. Fewer compatibility issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Streaming and Real-Time Needs
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Some architectures handle real-time better than others.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;REST is not designed for streaming or real-time updates, though it can be extended with techniques like Server-Sent Events or WebSockets. GraphQL supports subscriptions for real-time updates but requires additional infrastructure. gRPC supports native streaming and bi-directional communication, making it ideal for real-time and event-driven systems.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Use REST for standard request-response APIs. Use GraphQL subscriptions when your UI needs real-time updates with flexible queries. Use gRPC for real-time event streams and high-performance internal communication.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Better real-time support. More efficient streaming. Cleaner architecture for live data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tooling and Ecosystem
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Tooling affects how fast you can build and debug.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;REST has the largest ecosystem with tools like Postman, Swagger, and OpenAPI, making it easy to explore and test APIs. GraphQL has mature tooling like Apollo, GraphiQL, and schema introspection, which improves developer experience for complex queries. gRPC has strong tooling for service definition and code generation, but it requires more setup and is less browser-friendly.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Use REST if you want broad tooling support and easy debugging. Use GraphQL if you want schema-driven development and query explorers. Use gRPC if you want contract-first development and code generation across languages.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Faster development cycles. Better debugging and introspection. Easier team onboarding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Team Preferences and Learning Curve
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Your team’s comfort matters.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;REST is easiest to learn and widely understood, making it ideal for teams with mixed experience. GraphQL has a moderate learning curve but offers powerful query capabilities once adopted. gRPC has the steepest learning curve due to protobuf schemas and RPC concepts, but it pays off in performance-critical systems.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Match the API style to your team’s expertise. Use REST for rapid onboarding and broad compatibility. Use GraphQL when your team values flexible data access. Use gRPC when performance and typed contracts are priorities.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Better adoption. Fewer style conflicts. More consistent code quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling Considerations
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Scaling means more than traffic.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When applications grow, API architecture affects how easy it is to maintain, how efficiently data moves, and how well your system handles load. REST scales well for simple services but can become chatty for complex data. GraphQL scales well for UI-heavy apps but needs careful query management. gRPC scales best for internal microservices under high load.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Think about the number of services, data complexity, latency requirements, and deployment environment.&lt;/p&gt;

&lt;p&gt;REST often works well for public APIs, simple CRUD apps, and broad client compatibility. GraphQL often works well for complex frontends, mobile apps with nested data, and rapidly evolving UI requirements. gRPC often works well for internal microservices, high-throughput systems, and low-latency, streaming needs.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Better long-term architecture. Improved maintainability. Fewer scaling surprises.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hybrid API Architectures
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Mixing API styles is now normal.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Many modern systems use a combination of REST, GraphQL, and gRPC to match different needs. For example, REST for public APIs, GraphQL for frontend flexibility, and gRPC for internal service communication.&lt;/p&gt;

&lt;p&gt;How to fix it&lt;br&gt;
Use REST where simplicity and compatibility matter. Use GraphQL where frontend flexibility matters. Use gRPC where performance and streaming matter.&lt;/p&gt;

&lt;p&gt;Benefits&lt;br&gt;
Best of all worlds. More flexible architecture. Fewer compromises.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q. Which API style is best for public APIs?&lt;/strong&gt;&lt;br&gt;
A. REST is usually best for public APIs due to its simplicity, caching, and broad compatibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. When should I choose GraphQL over REST?&lt;/strong&gt;&lt;br&gt;
A. Choose GraphQL when your frontend needs flexible, nested data without multiple round trips.mobilelive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Is gRPC better than REST for performance?&lt;/strong&gt;&lt;br&gt;
A. Yes, gRPC is generally faster and more efficient for internal, high-throughput communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Can I use GraphQL in mobile apps?&lt;/strong&gt;&lt;br&gt;
A. Yes, GraphQL is often used in mobile apps to reduce over-fetching and improve data efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Should I mix API styles in one project?&lt;/strong&gt;&lt;br&gt;
A. Yes, hybrid architectures are common and often the best approach for complex systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interesting Facts &amp;amp; Stats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;REST remains the most widely used API style and is deeply integrated with HTTP, making it simple and broadly compatible for public and browser-based systems. Reference: &lt;a href="https://restfulapi.net" rel="noopener noreferrer"&gt;https://restfulapi.net&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GraphQL lets clients request exactly what they need, reducing payload size and round trips for complex UIs, especially in mobile and web applications. Reference: &lt;a href="https://graphql.org" rel="noopener noreferrer"&gt;https://graphql.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;gRPC is optimized for speed and efficiency, using binary protocols and HTTP/2 for internal communication, making it ideal for high-throughput microservices. Reference: &lt;a href="https://grpc.io" rel="noopener noreferrer"&gt;https://grpc.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Many modern systems use a combination of REST, GraphQL, and gRPC to match different needs, such as REST for public APIs, GraphQL for frontend flexibility, and gRPC for internal service communication. Reference: &lt;a href="https://www.apollographql.com/blog/why-use-graphql" rel="noopener noreferrer"&gt;https://www.apollographql.com/blog/why-use-graphql&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Choosing the right architecture depends on your frontend needs, team skills, and scalability requirements, with hybrid approaches often delivering the best balance. Reference: &lt;a href="https://www.apollographql.com/blog/what-is-graphql-introduction" rel="noopener noreferrer"&gt;https://www.apollographql.com/blog/what-is-graphql-introduction&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;REST, GraphQL, and gRPC are all excellent API architectures, but they excel in different areas. REST is the standard choice for public, browser-friendly APIs and simple CRUD systems. GraphQL gives clients flexible, fine-grained data fetching, ideal for complex UIs. gRPC excels in high-performance, internal microservices using binary protocols.&lt;/p&gt;

&lt;p&gt;A strong choice usually comes down to your client needs, performance requirements, team experience, and long-term scalability. When these factors align with the right API style, you get a system that is faster to build, easier to maintain, and ready to grow.&lt;/p&gt;

&lt;p&gt;About the Author: Lakashya is a full‑stack Laravel developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWeb Solution&lt;/a&gt; specializing in scalable, real‑time applications with PHP and modern frontends.&lt;/p&gt;

</description>
      <category>apiarchitecture</category>
      <category>rest</category>
      <category>graphql</category>
      <category>grpc</category>
    </item>
    <item>
      <title>AI Agents vs AI Workflows vs AI Automation</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Fri, 17 Jul 2026 10:49:28 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/ai-agents-vs-ai-workflows-vs-ai-automation-7mf</link>
      <guid>https://dev.to/addwebsolutionpvtltd/ai-agents-vs-ai-workflows-vs-ai-automation-7mf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Automation follows instructions. Workflows orchestrate tasks. Agents pursue goals."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AI Automation follows predefined rules with little or no decision-making.&lt;/li&gt;
&lt;li&gt;AI Workflows combine multiple AI and software components into structured business processes.&lt;/li&gt;
&lt;li&gt;AI Agents can reason, plan, use tools, and make decisions to accomplish goals.&lt;/li&gt;
&lt;li&gt;AI Automation is ideal for repetitive, rule-based tasks.&lt;/li&gt;
&lt;li&gt;AI Workflows are best for multi-step processes involving AI.&lt;/li&gt;
&lt;li&gt;AI Agents excel in dynamic environments where objectives remain the same but execution varies.&lt;/li&gt;
&lt;li&gt;Many modern enterprise solutions combine automation, workflows, and agents into hybrid systems.&lt;/li&gt;
&lt;li&gt;Major AI platforms including OpenAI, Anthropic, Google, Microsoft, AWS, and Salesforce are investing heavily in agentic AI.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Artificial Intelligence is transforming how businesses operate. However, terms like AI Automation, AI Workflows, and AI Agents are often used interchangeably, despite representing different levels of intelligence and autonomy.&lt;/p&gt;

&lt;p&gt;Understanding these concepts is essential for architects, developers, product managers, and business leaders designing AI-powered systems.&lt;br&gt;
Imagine three scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A chatbot automatically sends order confirmations.&lt;/li&gt;
&lt;li&gt;A document processing pipeline extracts invoice details, validates data, and updates an ERP system.&lt;/li&gt;
&lt;li&gt;An AI assistant independently researches suppliers, compares pricing, negotiates through APIs, and recommends the best vendor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although all three use AI, they differ significantly in their capabilities.&lt;br&gt;
At a high level:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI Automation executes predefined actions.&lt;/li&gt;
&lt;li&gt;AI Workflows coordinate structured sequences of AI-enabled tasks.&lt;/li&gt;
&lt;li&gt;AI Agents pursue goals by reasoning, planning, and adapting to changing conditions.
Understanding when to use each approach can significantly improve scalability, cost efficiency, and user experience.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is AI Automation?&lt;/li&gt;
&lt;li&gt;What are AI Workflows?&lt;/li&gt;
&lt;li&gt;What are AI Agents?&lt;/li&gt;
&lt;li&gt;Evolution of Intelligent Systems&lt;/li&gt;
&lt;li&gt;Core Components&lt;/li&gt;
&lt;li&gt;AI Automation vs AI Workflows vs AI Agents&lt;/li&gt;
&lt;li&gt;Architecture Comparison&lt;/li&gt;
&lt;li&gt;Automation Flow&lt;/li&gt;
&lt;li&gt;Workflow Flow&lt;/li&gt;
&lt;li&gt;Agent Flow&lt;/li&gt;
&lt;li&gt;Enterprise Use Cases&lt;/li&gt;
&lt;li&gt;Backend Implementation Example&lt;/li&gt;
&lt;li&gt;Benefits of Each Approach&lt;/li&gt;
&lt;li&gt;Challenges &amp;amp; Considerations&lt;/li&gt;
&lt;li&gt;Best Practices&lt;/li&gt;
&lt;li&gt;Hybrid Agentic Workflows&lt;/li&gt;
&lt;li&gt;Real-World Examples&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;Stats&lt;/li&gt;
&lt;li&gt;FAQs&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is AI Automation?
&lt;/h2&gt;

&lt;p&gt;AI Automation refers to the use of artificial intelligence within predefined business processes to execute repetitive tasks automatically.&lt;/p&gt;

&lt;p&gt;Unlike traditional automation, AI Automation can process unstructured data such as text, images, emails, and documents.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Email classification&lt;/li&gt;
&lt;li&gt;Invoice processing&lt;/li&gt;
&lt;li&gt;Customer support ticket routing&lt;/li&gt;
&lt;li&gt;Data extraction from PDFs&lt;/li&gt;
&lt;li&gt;Sentiment analysis&lt;/li&gt;
&lt;li&gt;OCR-based document processing
The automation logic is predefined, while AI performs specific tasks within that logic
Example: AI Automation
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;send_to_accounting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;notify_customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;process_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this example, every invoice follows the same predefined logic. The AI may extract invoice data, but the execution flow never changes. &lt;/p&gt;
&lt;h2&gt;
  
  
  What are AI Workflows?
&lt;/h2&gt;

&lt;p&gt;AI Workflows connect multiple AI models, APIs, databases, and business systems into a structured process.&lt;/p&gt;

&lt;p&gt;Rather than performing a single task, workflows orchestrate several interconnected steps.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer onboarding&lt;/li&gt;
&lt;li&gt;Insurance claim processing&lt;/li&gt;
&lt;li&gt;Resume screening&lt;/li&gt;
&lt;li&gt;Loan approval pipelines&lt;/li&gt;
&lt;li&gt;Marketing campaign generation&lt;/li&gt;
&lt;li&gt;Medical report summarization
Each step has a defined sequence, allowing AI to enhance specific stages while maintaining overall process control.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: AI Workflow&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extract_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;validated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;validate_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;validated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;fraud_check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;create_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;send_confirmation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, multiple AI-powered steps are orchestrated in a fixed sequence to complete a business process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are AI Agents?
&lt;/h2&gt;

&lt;p&gt;AI Agents are intelligent software systems capable of pursuing goals autonomously.&lt;/p&gt;

&lt;p&gt;Unlike workflows, agents are not limited to fixed execution paths.&lt;br&gt;
They can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand objectives&lt;/li&gt;
&lt;li&gt;Plan multiple steps&lt;/li&gt;
&lt;li&gt;Use external tools&lt;/li&gt;
&lt;li&gt;Search databases&lt;/li&gt;
&lt;li&gt;Call APIs&lt;/li&gt;
&lt;li&gt;Analyze results&lt;/li&gt;
&lt;li&gt;Adapt based on feedback&lt;/li&gt;
&lt;li&gt;Retry failed actions&lt;/li&gt;
&lt;li&gt;Learn from previous interactions (depending on implementation)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: AI Agent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;goal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Find the most cost-effective cloud provider&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;search_web&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;pricing_api&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;calculator&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike workflows, the agent decides which tools to use and in what order to achieve the user's goal.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI coding assistants&lt;/li&gt;
&lt;li&gt;Autonomous research assistants&lt;/li&gt;
&lt;li&gt;Personal productivity assistants&lt;/li&gt;
&lt;li&gt;Multi-agent customer service systems&lt;/li&gt;
&lt;li&gt;Financial analysis assistants&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Evolution of Intelligent Systems
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Traditional Automation
↓
Rule-Based Automation
↓
AI Automation
↓
AI Workflows
↓
AI Agents
↓
Multi-Agent Systems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The progression reflects increasing autonomy, adaptability, and decision-making capability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. AI Models&lt;/strong&gt;&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large Language Models (LLMs)&lt;/li&gt;
&lt;li&gt;Vision Models&lt;/li&gt;
&lt;li&gt;Speech Models&lt;/li&gt;
&lt;li&gt;Embedding Models
These models provide reasoning, understanding, and content generation capabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Workflow Engine&lt;/strong&gt;&lt;br&gt;
Responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task sequencing&lt;/li&gt;
&lt;li&gt;Conditional branching&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Retry mechanisms&lt;/li&gt;
&lt;li&gt;API orchestration
Examples include workflow orchestration platforms and low-code automation tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Agent Framework&lt;/strong&gt;&lt;br&gt;
Provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Planning&lt;/li&gt;
&lt;li&gt;Memory&lt;/li&gt;
&lt;li&gt;Tool usage&lt;/li&gt;
&lt;li&gt;Goal decomposition&lt;/li&gt;
&lt;li&gt;Decision-making&lt;/li&gt;
&lt;li&gt;Autonomous execution&lt;/li&gt;
&lt;li&gt;Agent Decision Loop
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;goal_completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;AI agents continuously plan, execute actions, observe outcomes, and adjust their strategy until the goal is achieved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. External Tools&lt;/strong&gt;&lt;br&gt;
Agents and workflows commonly interact with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;Search engines&lt;/li&gt;
&lt;li&gt;CRM systems&lt;/li&gt;
&lt;li&gt;ERP platforms&lt;/li&gt;
&lt;li&gt;Email services&lt;/li&gt;
&lt;li&gt;Calendars&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;Vector databases&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  AI Automation vs AI Workflows vs AI Agents
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzw78azw0xo9y4eshprrx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzw78azw0xo9y4eshprrx.png" alt=" " width="582" height="374"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture Comparison
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"Automation executes tasks, workflows coordinate processes, but AI agents pursue goals with intelligence and adaptability." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;AI Automation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
↓
Business Rule
↓
AI Model
↓
Action
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AI Workflow&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
↓
Workflow Engine
↓
AI Model
↓
Business Logic
↓
External APIs
↓
Final Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AI Agent&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Goal
↓
Planner
↓
Memory
↓
Reasoning Engine
↓
Tool Selection
↓
External Systems
↓
Observation
↓
Decision
↓
Goal Completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Automation Flow&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Incoming Email
↓
AI Classifies Email
↓
Move to Correct Department
↓
Send Confirmation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All steps follow predefined rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workflow Flow&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer Uploads Invoice
↓
OCR Extraction
↓
AI Validation
↓
Fraud Detection
↓
ERP Integration
↓
Manager Approval
↓
Payment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple AI capabilities are orchestrated in sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agent Flow&lt;/strong&gt;&lt;br&gt;
User Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Find the cheapest cloud provider for hosting my application."
↓
Research Providers
↓
Compare Pricing
↓
Analyze Features
↓
Estimate Monthly Cost
↓
Generate Recommendation
↓
Answer User
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The execution path adapts based on available information and intermediate results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Implementation Example
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AI Workflow (Python)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extract_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;validated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;validate_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;validated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;fraud_check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;create_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;send_confirmation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AI Agent (Python)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;goal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Compare cloud providers and recommend the best option.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;search_web&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;pricing_api&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;calculator&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workflow follows predefined steps, whereas the agent determines its own execution strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of AI Automation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Reduces manual effort&lt;/li&gt;
&lt;li&gt;Improves operational efficiency&lt;/li&gt;
&lt;li&gt;Faster task execution&lt;/li&gt;
&lt;li&gt;Consistent outputs&lt;/li&gt;
&lt;li&gt;Lower operational costs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits of AI Workflows
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Handles complex business processes&lt;/li&gt;
&lt;li&gt;Integrates multiple AI services&lt;/li&gt;
&lt;li&gt;Easier monitoring and auditing&lt;/li&gt;
&lt;li&gt;Improved scalability&lt;/li&gt;
&lt;li&gt;Better process orchestration&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits of AI Agents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adaptive decision-making&lt;/li&gt;
&lt;li&gt;Autonomous task execution&lt;/li&gt;
&lt;li&gt;Goal-oriented reasoning&lt;/li&gt;
&lt;li&gt;Reduced human intervention&lt;/li&gt;
&lt;li&gt;Continuous tool utilization&lt;/li&gt;
&lt;li&gt;Better handling of ambiguous requests&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges &amp;amp; Considerations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AI Automation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited flexibility&lt;/li&gt;
&lt;li&gt;Difficult to handle unexpected scenarios&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;AI Workflows&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Workflow maintenance&lt;/li&gt;
&lt;li&gt;Complex integrations&lt;/li&gt;
&lt;li&gt;Dependency management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;AI Agents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher infrastructure cost&lt;/li&gt;
&lt;li&gt;Longer execution times&lt;/li&gt;
&lt;li&gt;Hallucination risks&lt;/li&gt;
&lt;li&gt;Tool permission management&lt;/li&gt;
&lt;li&gt;Security considerations&lt;/li&gt;
&lt;li&gt;Monitoring autonomous behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Start with Automation&lt;/strong&gt;&lt;br&gt;
Automate repetitive tasks before introducing agents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Build Structured Workflows&lt;/strong&gt;&lt;br&gt;
Clearly define business processes before adding AI reasoning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Use Agents Only When Needed&lt;/strong&gt;&lt;br&gt;
Not every problem requires autonomous AI.&lt;/p&gt;

&lt;p&gt;Agents provide the greatest value when goals are complex and execution paths are unpredictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Human-in-the-Loop&lt;/strong&gt;&lt;br&gt;
For critical business decisions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Financial approvals&lt;/li&gt;
&lt;li&gt;Medical recommendations&lt;/li&gt;
&lt;li&gt;Legal documents&lt;/li&gt;
&lt;li&gt;Security operations
Always include human oversight.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Monitor AI Decisions&lt;/strong&gt;&lt;br&gt;
Track:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agent actions&lt;/li&gt;
&lt;li&gt;Tool usage&lt;/li&gt;
&lt;li&gt;API calls&lt;/li&gt;
&lt;li&gt;Decision history&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;li&gt;Success rates&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Hybrid Agentic Workflows
&lt;/h2&gt;

&lt;p&gt;Modern enterprise AI often combines all three approaches.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer submits a support request.
↓
AI Automation categorizes the request.
↓
AI Workflow gathers customer history, retrieves documentation, and prepares context.
↓
AI Agent analyzes the issue, selects the appropriate tools, proposes a resolution, and drafts a response.
↓
Human approval (if required).
↓
Response sent automatically.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hybrid model balances efficiency, predictability, and intelligent decision-making.&lt;/p&gt;

&lt;p&gt;Example: Tool Calling&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Schedule a meeting tomorrow at 2 PM.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;calendar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_event&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_call&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;calendar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates how modern AI agents interact with external systems such as calendars, CRMs, databases, and APIs while completing a workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Examples
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"The future of enterprise AI isn't choosing between automation, workflows, or agents - it's orchestrating all three to build systems that are efficient, scalable, and autonomous." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;AI Automation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic email classification&lt;/li&gt;
&lt;li&gt;Spam detection&lt;/li&gt;
&lt;li&gt;Document tagging&lt;/li&gt;
&lt;li&gt;Receipt processing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;AI Workflows&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Employee onboarding&lt;/li&gt;
&lt;li&gt;Insurance claims&lt;/li&gt;
&lt;li&gt;Loan approvals&lt;/li&gt;
&lt;li&gt;Healthcare documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;AI Agents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI coding assistants&lt;/li&gt;
&lt;li&gt;Autonomous customer support&lt;/li&gt;
&lt;li&gt;Research assistants&lt;/li&gt;
&lt;li&gt;Financial planning assistants&lt;/li&gt;
&lt;li&gt;Personal productivity agents&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;p&gt;1.AI automation has existed for decades, but generative AI has dramatically expanded what can be automated. &lt;a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-economic-potential-of-generative-ai-the-next-productivity-frontier" rel="noopener noreferrer"&gt;https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-economic-potential-of-generative-ai-the-next-productivity-frontier&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Large Language Models have transformed traditional workflows by enabling reasoning over natural language instead of relying solely on predefined rules. &lt;a href="https://arxiv.org/abs/2303.08774" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2303.08774&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.AI agents can plan tasks, use external tools, observe results, and iterate toward goals rather than following fixed execution paths.&lt;a href="https://arxiv.org/abs/2308.11432" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2308.11432&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.Multi-agent systems allow specialized AI agents to collaborate on complex problems like software development, scientific research, and planning. &lt;a href="https://arxiv.org/abs/2402.01680" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2402.01680&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.Modern enterprise AI platforms increasingly combine workflows, automation, retrieval, and autonomous agents instead of using a single approach. &lt;a href="https://cloud.google.com/blog/products/ai-machine-learning/agents-and-agentic-ai" rel="noopener noreferrer"&gt;https://cloud.google.com/blog/products/ai-machine-learning/agents-and-agentic-ai&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;According to McKinsey's "The Economic Potential of Generative AI" report, generative AI could add between $2.6 trillion and $4.4 trillion annually to the global economy by improving productivity across industries.
&lt;a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-economic-potential-of-generative-ai-the-next-productivity-frontier" rel="noopener noreferrer"&gt;https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-economic-potential-of-generative-ai-the-next-productivity-frontier&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Deloitte's State of Generative AI in the Enterprise reports that more than 70% of organizations are exploring or experimenting with generative AI to improve business processes and operational efficiency.&lt;a href="https://www2.deloitte.com/us/en/pages/consulting/articles/state-of-generative-ai-in-enterprise.html" rel="noopener noreferrer"&gt;https://www2.deloitte.com/us/en/pages/consulting/articles/state-of-generative-ai-in-enterprise.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;According to IBM's Global AI Adoption Index, approximately 42% of large organizations have actively deployed AI in their operations, while many others are evaluating implementation. &lt;a href="https://www.ibm.com/reports/ai-adoption" rel="noopener noreferrer"&gt;https://www.ibm.com/reports/ai-adoption&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;McKinsey reports that organizations implementing AI successfully often see significant improvements in productivity, particularly in customer operations, software engineering, marketing, and knowledge work. &lt;a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai" rel="noopener noreferrer"&gt;https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q1. What is the difference between AI Automation and AI Workflows?&lt;/strong&gt;&lt;br&gt;
AI Automation focuses on automating individual tasks, while AI Workflows coordinate multiple AI-powered tasks into structured business processes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q2. How are AI Agents different from AI Workflows?&lt;/strong&gt;&lt;br&gt;
Workflows follow predefined sequences, whereas AI Agents dynamically decide how to achieve a goal based on context, available tools, and intermediate results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3. Do AI Agents always use Large Language Models?&lt;/strong&gt;&lt;br&gt;
Not necessarily. While many modern agents are powered by LLMs, agents can also leverage traditional machine learning models, rule-based logic, or a combination of techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q4. When should businesses use AI Agents?&lt;/strong&gt;&lt;br&gt;
AI Agents are most valuable for complex, open-ended problems where the execution path cannot be fully predefined and adaptability is essential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q5. Can Automation, Workflows, and Agents work together?&lt;/strong&gt;&lt;br&gt;
Yes. Many enterprise AI systems combine all three approaches - automation for repetitive tasks, workflows for process orchestration, and agents for intelligent decision-making.&lt;/p&gt;

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

&lt;p&gt;AI Automation, AI Workflows, and AI Agents are complementary approaches rather than competing technologies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI Automation delivers efficiency by executing repetitive, rule-based tasks.&lt;/li&gt;
&lt;li&gt;AI Workflows orchestrate multiple AI capabilities into reliable business processes.&lt;/li&gt;
&lt;li&gt;AI Agents introduce autonomy, reasoning, and adaptability for solving complex, goal-oriented problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As organizations embrace generative AI, the future lies in hybrid agentic systems that combine the predictability of workflows, the efficiency of automation, and the intelligence of autonomous agents.&lt;/p&gt;

&lt;p&gt;Choosing the right approach depends on the complexity of the problem, the level of decision-making required, governance needs, and the desired balance between control and autonomy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The future of enterprise AI isn't choosing between automation, workflows, or agents - it's orchestrating them together to build intelligent systems that are efficient, adaptable, and scalable."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;About the Author:&lt;em&gt;Mayank is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;, building scalable apps with PHP, Node.js &amp;amp; React. Sharing ideas, code, and creativity.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>llm</category>
      <category>agentaichallenge</category>
    </item>
    <item>
      <title>Optimistic vs Pessimistic Locking: Preventing Concurrent Database Conflicts</title>
      <dc:creator>Vatsal Acharya</dc:creator>
      <pubDate>Mon, 13 Jul 2026 08:11:02 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/optimistic-vs-pessimistic-locking-preventing-concurrent-database-conflicts-lfg</link>
      <guid>https://dev.to/addwebsolutionpvtltd/optimistic-vs-pessimistic-locking-preventing-concurrent-database-conflicts-lfg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Concurrency bugs aren't caused by fast systems - they're caused by systems that assume they're the only ones running."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Learn why concurrent database updates cause data corruption.&lt;/li&gt;
&lt;li&gt;Understand race conditions with simple real-world examples.&lt;/li&gt;
&lt;li&gt;Learn the difference between Optimistic and Pessimistic Locking.&lt;/li&gt;
&lt;li&gt;Know when each locking strategy should be used.&lt;/li&gt;
&lt;li&gt;Implement both techniques in Laravel.&lt;/li&gt;
&lt;li&gt;Compare MySQL and PostgreSQL behavior.&lt;/li&gt;
&lt;li&gt;Avoid deadlocks and lost updates.&lt;/li&gt;
&lt;li&gt;Learn production best practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why Database Conflicts Happen&lt;/li&gt;
&lt;li&gt;Understanding Race Conditions&lt;/li&gt;
&lt;li&gt;What is Database Locking?&lt;/li&gt;
&lt;li&gt;Types of Database Locking&lt;/li&gt;
&lt;li&gt;Optimistic Locking&lt;/li&gt;
&lt;li&gt;How Optimistic Locking Works&lt;/li&gt;
&lt;li&gt;Optimistic Locking Example&lt;/li&gt;
&lt;li&gt;Laravel Implementation&lt;/li&gt;
&lt;li&gt;Pessimistic Locking&lt;/li&gt;
&lt;li&gt;How Pessimistic Locking Works&lt;/li&gt;
&lt;li&gt;Laravel Implementation&lt;/li&gt;
&lt;li&gt;Shared Lock vs Exclusive Lock&lt;/li&gt;
&lt;li&gt;Database Transaction Isolation Levels&lt;/li&gt;
&lt;li&gt;Deadlocks&lt;/li&gt;
&lt;li&gt;Performance Comparison&lt;/li&gt;
&lt;li&gt;Real World Examples&lt;/li&gt;
&lt;li&gt;Which One Should You Choose?&lt;/li&gt;
&lt;li&gt;Common Mistakes&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;FAQs&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Database Conflicts Happen
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine your bank account contains&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Balance = $1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two users try to withdraw money simultaneously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User A Withdraws $200
User B Withdraws $300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both requests arrive at exactly the same time.&lt;br&gt;
Both read&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Balance = $1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User A writes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User B writes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final balance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Money magically appeared.&lt;br&gt;
This is called a &lt;strong&gt;Race Condition.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another Example&lt;/strong&gt;&lt;br&gt;
Suppose an e-commerce website has&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 iPhone left
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two customers click&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Buy Now
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;at exactly the same moment.&lt;br&gt;
Without locking&lt;br&gt;
Customer A purchases.&lt;br&gt;
Customer B also purchases.&lt;br&gt;
Now inventory becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Does This Happen?&lt;/strong&gt;&lt;br&gt;
A database operation usually follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Data
↓
Process Data
↓
Update Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If two users perform this sequence simultaneously,&lt;br&gt;
both read the same old value.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding Race Conditions
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time →
User A
Read Balance =1000
------------------------
User B
Read Balance =1000
------------------------
User A
Write 800
------------------------
User B
Write 700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;User A's update is lost.&lt;br&gt;
This is called &lt;strong&gt;Lost Update Problem&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Database Locking?
&lt;/h2&gt;

&lt;p&gt;Database locking is a mechanism that prevents multiple transactions from modifying the same data in conflicting ways.&lt;/p&gt;

&lt;p&gt;Think of it like a meeting room.&lt;/p&gt;

&lt;p&gt;If someone is inside,&lt;br&gt;
others must wait,&lt;/p&gt;

&lt;p&gt;or check whether the room changed before entering.&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of Database Locking
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"A transaction protects a unit of work; a locking strategy protects the integrity of shared data."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two major strategies exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Optimistic Locking
Pessimistic Locking
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optimistic Locking
&lt;/h2&gt;

&lt;p&gt;Optimistic locking assumes &lt;strong&gt;Conflicts are rare.&lt;/strong&gt;&lt;br&gt;
Instead of locking rows,&lt;br&gt;
everyone can read and modify.&lt;br&gt;
Before saving,&lt;br&gt;
the application checks&lt;br&gt;
&lt;strong&gt;"Has someone already modified this record?"&lt;/strong&gt;&lt;br&gt;
If yes&lt;br&gt;
&lt;strong&gt;Update fails.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real Life Example&lt;/strong&gt;&lt;br&gt;
Imagine editing a Google Doc.&lt;br&gt;
Two people open the same document.&lt;br&gt;
You save first.&lt;br&gt;
When the second user saves,&lt;br&gt;
Google says&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This document has changed.
Please reload.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's optimistic locking.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Optimistic Locking Works
&lt;/h2&gt;

&lt;p&gt;Usually via&lt;br&gt;
&lt;strong&gt;version&lt;/strong&gt; or &lt;strong&gt;updated_at&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example table&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvmzv6ezgoml97ast2y8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvmzv6ezgoml97ast2y8d.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;User A reads&lt;br&gt;
&lt;code&gt;&lt;br&gt;
Version =5&lt;br&gt;
&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
User B reads&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Version =5&lt;br&gt;
&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
User A updates&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;br&gt;
WHERE version =5&lt;br&gt;
&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
Database changes&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;br&gt;
version=6&lt;br&gt;
&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
User B tries&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;br&gt;
WHERE version=5&lt;br&gt;
&lt;/code&gt;`plaintext&lt;br&gt;
No rows affected.&lt;br&gt;
Conflict detected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimistic Locking Example
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
UPDATE products&lt;br&gt;
SET stock = 5,&lt;br&gt;
version = version +1&lt;br&gt;
WHERE&lt;br&gt;
id=1&lt;br&gt;
AND version=5;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
If&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Affected Rows =0&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
Someone modified it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Laravel Implementation
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
$product = Product::find(1);&lt;br&gt;
$currentVersion = $product-&amp;gt;version;&lt;br&gt;
$updated = Product::where('id', 1)&lt;br&gt;
   -&amp;gt;where('version', $currentVersion)&lt;br&gt;
   -&amp;gt;update([&lt;br&gt;
       'stock' =&amp;gt; 5,&lt;br&gt;
       'version' =&amp;gt; $currentVersion + 1,&lt;br&gt;
   ]);&lt;br&gt;
if (! $updated) {&lt;br&gt;
   throw new Exception('Record has been modified by another user.');&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very fast&lt;/li&gt;
&lt;li&gt;No waiting&lt;/li&gt;
&lt;li&gt;Excellent scalability&lt;/li&gt;
&lt;li&gt;High throughput&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update may fail&lt;/li&gt;
&lt;li&gt;User may retry&lt;/li&gt;
&lt;li&gt;More application logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pessimistic Locking
&lt;/h2&gt;

&lt;p&gt;Pessimistic locking assumes Conflicts are likely.&lt;br&gt;
Before updating,&lt;br&gt;
the database locks the row.&lt;br&gt;
Nobody else may modify it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
ATM withdraw&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Balance =1000&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
User A begins transaction&lt;br&gt;
Database locks row.&lt;br&gt;
User B tries&lt;br&gt;
Wait...&lt;br&gt;
User A commits.&lt;br&gt;
Only then&lt;br&gt;
User B proceeds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timeline&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
User A&lt;br&gt;
Lock Row&lt;br&gt;
↓&lt;br&gt;
Update&lt;br&gt;
↓&lt;br&gt;
Commit&lt;br&gt;
↓&lt;/p&gt;

&lt;h2&gt;
  
  
  Unlock
&lt;/h2&gt;

&lt;p&gt;User B&lt;br&gt;
Wait...&lt;br&gt;
↓&lt;br&gt;
Lock&lt;br&gt;
↓&lt;br&gt;
Update&lt;br&gt;
↓&lt;br&gt;
Commit&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;h2&gt;
  
  
  How Pessimistic Locking Works
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
BEGIN;&lt;br&gt;
SELECT *&lt;br&gt;
FROM accounts&lt;br&gt;
WHERE id=1&lt;br&gt;
FOR UPDATE;&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance -200;&lt;br&gt;
COMMIT;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;h2&gt;
  
  
  Laravel Implementation
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
DB::transaction(function () {&lt;br&gt;
   $account = Account::where('id', 1)&lt;br&gt;
       -&amp;gt;lockForUpdate()&lt;br&gt;
       -&amp;gt;first();&lt;br&gt;
   $account-&amp;gt;balance -= 200;&lt;br&gt;
   $account-&amp;gt;save();&lt;br&gt;
});&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
Laravel automatically generates&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
SELECT ...&lt;br&gt;
FOR UPDATE&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared Lock vs Exclusive Lock
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Shared Lock&lt;/strong&gt;&lt;br&gt;
Allows&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Read&lt;br&gt;
Read&lt;br&gt;
Read&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;plaintext&lt;br&gt;
But&lt;br&gt;
No updates.&lt;br&gt;
Laravel&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
DB::table('users')&lt;br&gt;
   -&amp;gt;sharedLock()&lt;br&gt;
   -&amp;gt;get();&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;sql&lt;br&gt;
SQL&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
SELECT *&lt;br&gt;
FROM users&lt;/p&gt;

&lt;p&gt;LOCK IN SHARE MODE;&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;sql&lt;br&gt;
(MySQL) or &lt;strong&gt;FOR SHARE&lt;/strong&gt; (PostgreSQL).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exclusive Lock&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
Read ❌&lt;/p&gt;

&lt;p&gt;Write ❌&lt;/p&gt;

&lt;p&gt;Delete ❌&lt;br&gt;
&lt;code&gt;`plaintext&lt;br&gt;
Only the locking transaction proceeds.&lt;br&gt;
Generated by&lt;br&gt;
`&lt;/code&gt;&lt;br&gt;
FOR UPDATE&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;plaintext&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Transaction Isolation Levels
&lt;/h2&gt;

&lt;p&gt;An important concept that interacts with locking is transaction isolation. Different isolation levels control what concurrent transactions can see and how they interact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhy15786riuqojuox9cym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhy15786riuqojuox9cym.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Behavior depends on the database engine. For example, MySQL's InnoDB uses next-key locking to reduce phantom reads under **REPEATABLE READ.&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;Include a brief explanation of:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Dirty Read:&lt;/strong&gt; Reading uncommitted data.&lt;br&gt;
&lt;strong&gt;- Non-repeatable Read:&lt;/strong&gt; Same row returns different values within one transaction.&lt;br&gt;
&lt;strong&gt;- Phantom Read:&lt;/strong&gt; A repeated query returns additional or missing rows due to inserts/deletes by another transaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deadlocks
&lt;/h2&gt;

&lt;p&gt;A deadlock occurs when two transactions wait on each other indefinitely.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
Transaction A&lt;br&gt;
Lock Order&lt;br&gt;
↓&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait Product
&lt;/h2&gt;

&lt;p&gt;Transaction B&lt;br&gt;
Lock Product&lt;br&gt;
↓&lt;br&gt;
Wait Order&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;php&lt;br&gt;
Neither can continue.&lt;br&gt;
Most modern databases detect deadlocks automatically and roll back one transaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to reduce deadlocks:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always lock resources in the same order.&lt;/li&gt;
&lt;li&gt;Keep transactions short.&lt;/li&gt;
&lt;li&gt;Avoid unnecessary locks.&lt;/li&gt;
&lt;li&gt;Commit or roll back promptly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Laravel Retry Example&lt;/strong&gt;&lt;br&gt;
Laravel's transaction helper can retry automatically when a deadlock occurs:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
DB::transaction(function () {&lt;br&gt;
   // Critical database operations&lt;br&gt;
}, 5); // Retry up to 5 times&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Comparison
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"Optimistic locking trusts that conflicts are rare. Pessimistic locking prepares for them before they happen. Great engineers know when to choose each."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7rxn1ygy3p5p45h98nww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7rxn1ygy3p5p45h98nww.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real World Examples&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn39ubcyy44dm5j93l35h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn39ubcyy44dm5j93l35h.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Which One Should You Choose?
&lt;/h2&gt;

&lt;p&gt;Choose &lt;strong&gt;Optimistic Locking&lt;/strong&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads greatly outnumber writes.&lt;/li&gt;
&lt;li&gt;Conflicts are uncommon.&lt;/li&gt;
&lt;li&gt;Scalability is a priority.&lt;/li&gt;
&lt;li&gt;Users can retry failed updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose &lt;strong&gt;Pessimistic Locking&lt;/strong&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every update must succeed in sequence.&lt;/li&gt;
&lt;li&gt;Data integrity is critical.&lt;/li&gt;
&lt;li&gt;Concurrent updates are common.&lt;/li&gt;
&lt;li&gt;Temporary blocking is acceptable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some systems combine both approaches - for example, optimistic locking for general edits and pessimistic locking for payment processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Assuming transactions automatically prevent lost updates.&lt;/li&gt;
&lt;li&gt;Holding transactions open while calling external APIs.&lt;/li&gt;
&lt;li&gt;Forgetting to handle optimistic lock failures.&lt;/li&gt;
&lt;li&gt;Locking more rows than necessary.&lt;/li&gt;
&lt;li&gt;Ignoring deadlock exceptions.&lt;/li&gt;
&lt;li&gt;Using pessimistic locks in high-traffic read-heavy workloads without measuring the impact.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Amazon, Uber and Stripe use optimistic locking in many high-read systems.&lt;/li&gt;
&lt;li&gt;Banking systems often rely on pessimistic locking. &lt;a href="https://learn.microsoft.com/en-us/sql/connect/jdbc/understanding-isolation-levels?view=sql-server-ver17" rel="noopener noreferrer"&gt;source&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Most developers encounter concurrency bugs only after production deployment.&lt;/li&gt;
&lt;li&gt;Locking is one of the hardest backend topics because bugs are often random and difficult to reproduce.&lt;/li&gt;
&lt;li&gt;Transactions alone do not always prevent lost updates. &lt;a href="https://www.postgresql.org/docs/current/transaction-iso.html" rel="noopener noreferrer"&gt;source&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can transactions replace locking?&lt;/strong&gt;&lt;br&gt;
No. Transactions define the boundaries of a unit of work, but depending on the isolation level and the operations performed, they may not prevent concurrent update conflicts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does Laravel support optimistic locking out of the box?&lt;/strong&gt;&lt;br&gt;
Laravel provides lockForUpdate() and sharedLock() for pessimistic locking. Optimistic locking is not built into Eloquent, but it is straightforward to implement using a version column or timestamp check.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does updated_at work for optimistic locking?&lt;/strong&gt;&lt;br&gt;
Yes, but a dedicated integer version column is generally more reliable because timestamps can have precision and synchronization limitations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is pessimistic locking slower?&lt;/strong&gt;&lt;br&gt;
It can reduce throughput because other transactions may have to wait for locks to be released.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can deadlocks still happen?&lt;/strong&gt;&lt;br&gt;
Yes. Even with proper locking, deadlocks are possible, so applications should handle deadlock exceptions and retry when appropriate.&lt;/p&gt;

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

&lt;p&gt;Concurrency issues are often invisible during development because they require multiple requests to collide at just the right moment. However, in production systems with many users, these situations become inevitable.&lt;/p&gt;

&lt;p&gt;Optimistic locking focuses on performance by detecting conflicts only when updates occur, making it ideal for read-heavy applications. Pessimistic locking prioritizes consistency by preventing conflicting updates before they happen, making it suitable for critical financial or inventory operations.&lt;/p&gt;

&lt;p&gt;Understanding both strategies - and knowing when to use each - is a fundamental backend engineering skill. Combined with well-designed transactions, appropriate isolation levels, and careful error handling, they help build applications that remain reliable under real-world load.&lt;/p&gt;

&lt;p&gt;About the Author:&lt;em&gt;Vatsal is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;. Building web magic with Laravel, PHP, MySQL, Vue.js &amp;amp; more.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>laravel</category>
      <category>mysql</category>
      <category>postgres</category>
    </item>
    <item>
      <title>RAG and Vector Databases for Beginners (How Modern AI Finds the Right Information)</title>
      <dc:creator>Ankit Parmar</dc:creator>
      <pubDate>Mon, 29 Jun 2026 12:17:43 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/rag-and-vector-databases-for-beginners-how-modern-ai-finds-the-right-information-e55</link>
      <guid>https://dev.to/addwebsolutionpvtltd/rag-and-vector-databases-for-beginners-how-modern-ai-finds-the-right-information-e55</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“The goal is to turn data into information, and information into insight.” -  Carly Fiorina&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Artificial Intelligence has come a long way in a short time. Today, applications can answer questions, summarize documents, write code, and even assist with customer support. But behind all the excitement lies a challenge that every developer eventually encounters:&lt;/p&gt;

&lt;p&gt;AI models do not automatically know your data.&lt;/p&gt;

&lt;p&gt;Your product documentation, internal knowledge base, customer support articles, company policies, and business records are not magically available to a language model. Even the most advanced AI systems can only work with information they were trained on or information provided at runtime.&lt;/p&gt;

&lt;p&gt;This is where Retrieval-Augmented Generation (RAG) and Vector Databases enter the picture.&lt;/p&gt;

&lt;p&gt;Over the last few years, RAG has become one of the most important architectural patterns in AI development. Whether you're building an internal company assistant, a document search engine, a customer support chatbot, or an AI-powered learning platform, chances are you'll encounter RAG sooner rather than later.&lt;/p&gt;

&lt;p&gt;In this article, we'll break down what RAG is, how vector databases work, and why so many engineering teams are adopting this approach instead of relying solely on language models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;RAG combines retrieval and generation&lt;/li&gt;
&lt;li&gt;Vector databases enable semantic search&lt;/li&gt;
&lt;li&gt;AI retrieves information before generating responses&lt;/li&gt;
&lt;li&gt;Reduces hallucinations significantly&lt;/li&gt;
&lt;li&gt;Works with private and frequently changing data&lt;/li&gt;
&lt;li&gt;Eliminates the need for constant retraining&lt;/li&gt;
&lt;li&gt;Powers many modern enterprise AI applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why Traditional AI Falls Short&lt;/li&gt;
&lt;li&gt;Why RAG Became So Important&lt;/li&gt;
&lt;li&gt;What Is RAG?&lt;/li&gt;
&lt;li&gt;What Is a Vector Database?&lt;/li&gt;
&lt;li&gt;Understanding Embeddings&lt;/li&gt;
&lt;li&gt;RAG Architecture Overview&lt;/li&gt;
&lt;li&gt;The Retrieval Flow Explained&lt;/li&gt;
&lt;li&gt;Why Vector Search Beats Keyword Search&lt;/li&gt;
&lt;li&gt;Popular Vector Databases&lt;/li&gt;
&lt;li&gt;Real-World Use Cases&lt;/li&gt;
&lt;li&gt;Why This Architecture Makes Sense&lt;/li&gt;
&lt;li&gt;Watch Out For&lt;/li&gt;
&lt;li&gt;Next Steps You Can Take&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;FAQ&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Traditional AI Falls Short
&lt;/h2&gt;

&lt;p&gt;When most people first interact with modern AI, they assume it works like a search engine.&lt;br&gt;
Ask a question.&lt;br&gt;
Get an answer.&lt;br&gt;
Simple.&lt;br&gt;
But that's not actually what's happening.&lt;/p&gt;

&lt;p&gt;Language models generate responses based on patterns learned during training. They do not search the internet every time you ask a question, and they do not automatically have access to your company's latest information.&lt;/p&gt;

&lt;p&gt;This creates several problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Knowledge becomes outdated&lt;/li&gt;
&lt;li&gt;Private company data is inaccessible&lt;/li&gt;
&lt;li&gt;Hallucinations can occur&lt;/li&gt;
&lt;li&gt;Retraining models is expensive&lt;/li&gt;
&lt;li&gt;Context windows have practical limits
Imagine building a customer support assistant.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A customer asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How do I upgrade my enterprise subscription?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer might exist in your internal documentation, but unless that information is available to the model, the AI can only make an educated guess.&lt;/p&gt;

&lt;p&gt;And in business applications, guesses are dangerous.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why RAG Became So Important
&lt;/h2&gt;

&lt;p&gt;For years, developers assumed that the solution was model training.&lt;br&gt;
Need your AI to know company information?&lt;br&gt;
Train it.&lt;br&gt;
Need new information?&lt;br&gt;
Train it again.&lt;br&gt;
Need updated policies?&lt;br&gt;
Train it again.&lt;br&gt;
This approach quickly becomes expensive, slow, and difficult to maintain.&lt;/p&gt;

&lt;p&gt;Then came a much simpler idea:&lt;/p&gt;

&lt;p&gt;Instead of teaching the model everything, what if we taught it how to find information when needed?&lt;/p&gt;

&lt;p&gt;That's the core idea behind RAG.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The greatest challenge in information management is not storing data. It is finding the right data at the right time."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;RAG turns AI systems from knowledge containers into knowledge seekers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Information is the oil of the 21st century, and analytics is the combustion engine.” - Peter Sondergaard&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What Is RAG?
&lt;/h2&gt;

&lt;p&gt;RAG stands for Retrieval-Augmented Generation.&lt;br&gt;
The name sounds complicated, but the idea is surprisingly simple.&lt;br&gt;
Instead of asking an AI model to answer from memory:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for relevant information&lt;/li&gt;
&lt;li&gt;Retrieve useful content&lt;/li&gt;
&lt;li&gt;Add that content to the prompt&lt;/li&gt;
&lt;li&gt;Generate a response based on retrieved information&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Think of it like an experienced engineer.&lt;br&gt;
A good engineer doesn't memorize every piece of documentation.&lt;br&gt;
They know where to find it.&lt;br&gt;
RAG gives AI that same ability.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Vector Database?
&lt;/h2&gt;

&lt;p&gt;To understand RAG, you need to understand vector databases.&lt;br&gt;
Traditional databases store data in rows and columns.&lt;br&gt;
For example:&lt;br&gt;
ID   Name   Department&lt;br&gt;
1    John   Engineering&lt;br&gt;
2    Sarah  Marketing&lt;/p&gt;

&lt;p&gt;This works well for structured information.&lt;br&gt;
But AI needs something different.&lt;br&gt;
AI needs a way to understand meaning.&lt;br&gt;
That's where vectors come in.&lt;br&gt;
A vector is simply a numerical representation of information.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
Customer Support Article&lt;br&gt;
↓&lt;br&gt;
[0.23, -0.77, 0.91, ...]&lt;br&gt;
Instead of storing words directly, vector databases store mathematical representations of meaning.&lt;br&gt;
This allows AI systems to find similar information even when the wording is completely different.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Data is a precious thing and will last longer than the systems themselves.” -  Tim Berners-Lee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Understanding Embeddings
&lt;/h2&gt;

&lt;p&gt;Embeddings are the foundation of vector search.&lt;br&gt;
An embedding model converts text into numbers.&lt;br&gt;
For example:&lt;br&gt;
Dog&lt;br&gt;
↓&lt;br&gt;
[0.15, 0.44, -0.12]&lt;br&gt;
Puppy&lt;br&gt;
↓&lt;br&gt;
[0.17, 0.40, -0.10]&lt;br&gt;
The vectors are very close together because the meanings are similar.&lt;br&gt;
Now consider:&lt;br&gt;
Dog&lt;br&gt;
and&lt;br&gt;
Airplane&lt;br&gt;
Those vectors will be much farther apart.&lt;br&gt;
This allows computers to understand relationships between concepts.&lt;br&gt;
Not through grammar.&lt;br&gt;
Not through keywords.&lt;br&gt;
Through mathematical similarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  RAG Architecture Overview
&lt;/h2&gt;

&lt;p&gt;At a high level, a RAG system looks like this:&lt;br&gt;
User Question&lt;br&gt;
     ↓&lt;br&gt;
Embedding Model&lt;br&gt;
     ↓&lt;br&gt;
Vector Database&lt;br&gt;
     ↓&lt;br&gt;
Relevant Documents&lt;br&gt;
     ↓&lt;br&gt;
Language Model&lt;br&gt;
     ↓&lt;br&gt;
Final Answer&lt;br&gt;
The key difference is that the AI doesn't answer immediately.&lt;br&gt;
It searches first.&lt;br&gt;
That extra retrieval step changes everything.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The most valuable commodity of the 21st century will be data.” -  Clive Humby&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Retrieval Flow Explained
&lt;/h2&gt;

&lt;p&gt;Let's walk through a real example.&lt;br&gt;
Suppose a user asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How can I reset my password?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 1 - Question Becomes an Embedding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The user's question is converted into a vector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 - Similarity Search&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The vector database searches for similar vectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 - Document Retrieval&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The system finds:&lt;br&gt;
Password reset guide&lt;br&gt;
Authentication documentation&lt;br&gt;
Help center article&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 - Context Creation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The retrieved content is packaged into the prompt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5 - Response Generation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The language model generates an answer using actual documentation.&lt;br&gt;
The result is far more reliable than relying on model memory alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Vector Search Beats Keyword Search
&lt;/h2&gt;

&lt;p&gt;Traditional search systems depend heavily on exact matches.&lt;/p&gt;

&lt;p&gt;Suppose a document contains:&lt;br&gt;
Employee Leave Guidelines&lt;/p&gt;

&lt;p&gt;A user searches:&lt;br&gt;
Vacation Policy&lt;/p&gt;

&lt;p&gt;Keyword search may fail because the words don't match.&lt;br&gt;
Vector search succeeds because it understands that both concepts are related.&lt;/p&gt;

&lt;p&gt;This is called semantic search.&lt;br&gt;
Instead of searching for words, you're searching for meaning.&lt;br&gt;
That's a huge difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Popular Vector Databases
&lt;/h2&gt;

&lt;p&gt;Several vector databases have emerged as leaders in this space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pinecone&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Built specifically for vector search and AI applications.&lt;br&gt;
Popular because it handles scaling and infrastructure automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Qdrant&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open-source and developer-friendly.&lt;br&gt;
Widely used for production AI systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weaviate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Provides vector search with rich metadata filtering.&lt;br&gt;
Useful for enterprise applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Milvus&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Designed for large-scale workloads.&lt;br&gt;
Often used in high-volume environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PostgreSQL with pgvector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most interesting options.&lt;br&gt;
Instead of introducing a new database, developers can extend PostgreSQL to support vector search.&lt;br&gt;
This makes adoption much easier for existing teams.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Customer Support Assistants&lt;/strong&gt;&lt;br&gt;
Instead of hardcoding answers, AI retrieves support documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Internal Company Knowledge&lt;/strong&gt;&lt;br&gt;
Employees can search thousands of internal documents naturally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Educational Platforms&lt;/strong&gt;&lt;br&gt;
Students ask questions and receive answers based on course material.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Legal Document Search&lt;/strong&gt;&lt;br&gt;
Law firms retrieve relevant clauses and references from large document collections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Healthcare Knowledge Systems&lt;/strong&gt;&lt;br&gt;
Medical professionals search clinical guidelines and research papers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Architecture Makes Sense
&lt;/h2&gt;

&lt;p&gt;The biggest advantage of RAG is flexibility.&lt;br&gt;
Without RAG:&lt;br&gt;
Question&lt;br&gt;
  ↓&lt;br&gt;
LLM&lt;br&gt;
  ↓&lt;br&gt;
Answer&lt;br&gt;
With RAG:&lt;br&gt;
Question&lt;br&gt;
  ↓&lt;br&gt;
Search&lt;br&gt;
  ↓&lt;br&gt;
Relevant Information&lt;br&gt;
  ↓&lt;br&gt;
LLM&lt;br&gt;
  ↓&lt;br&gt;
Answer&lt;br&gt;
The second approach is grounded in actual information.&lt;br&gt;
That's why RAG has become the preferred solution for many enterprise AI systems.&lt;br&gt;
You can update documents instantly without retraining models.&lt;br&gt;
That's a massive operational advantage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch Out For
&lt;/h2&gt;

&lt;p&gt;RAG is powerful, but there are common mistakes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Poor Document Chunking&lt;/strong&gt;&lt;br&gt;
Chunks that are too large or too small hurt retrieval quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Low-Quality Source Data&lt;/strong&gt;&lt;br&gt;
Bad data leads to bad answers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Too Much Context&lt;/strong&gt;&lt;br&gt;
More context isn't always better.&lt;br&gt;
Too much information can confuse the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weak Embedding Models&lt;/strong&gt;&lt;br&gt;
The quality of retrieval depends heavily on embedding quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ignoring Relevance Ranking&lt;/strong&gt;&lt;br&gt;
Not all retrieved documents should have equal importance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps You Can Take
&lt;/h2&gt;

&lt;p&gt;If you're interested in experimenting with RAG:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn how embeddings work&lt;/li&gt;
&lt;li&gt;Explore vector similarity search&lt;/li&gt;
&lt;li&gt;Install pgvector on PostgreSQL&lt;/li&gt;
&lt;li&gt;Build a simple document Q&amp;amp;A system&lt;/li&gt;
&lt;li&gt;Experiment with document chunking strategies&lt;/li&gt;
&lt;li&gt;Add citations to generated answers
A simple RAG application is one of the best ways to understand modern AI architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Many enterprise AI systems rely on RAG instead of frequent model retraining.&lt;a href="https://cloud.google.com/use-cases/retrieval-augmented-generation" rel="noopener noreferrer"&gt;https://cloud.google.com/use-cases/retrieval-augmented-generation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Vector databases search based on meaning rather than exact keywords.&lt;a href="https://weaviate.io/developers/weaviate/concepts/search/vector-search" rel="noopener noreferrer"&gt;https://weaviate.io/developers/weaviate/concepts/search/vector-search&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Modern vector search engines can search millions of documents in milliseconds.&lt;a href="https://qdrant.tech/documentation" rel="noopener noreferrer"&gt;https://qdrant.tech/documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PostgreSQL can function as a vector database through the pgvector extension.&lt;a href="https://github.com/pgvector/pgvector" rel="noopener noreferrer"&gt;https://github.com/pgvector/pgvector&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RAG has become one of the most widely adopted patterns in enterprise AI development.&lt;a href="https://aws.amazon.com/what-is/retrieval-augmented-generation" rel="noopener noreferrer"&gt;https://aws.amazon.com/what-is/retrieval-augmented-generation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is RAG better than fine-tuning?&lt;/strong&gt;&lt;br&gt;
Not necessarily.&lt;br&gt;
They solve different problems.&lt;br&gt;
Fine-tuning changes model behavior.&lt;br&gt;
RAG provides external knowledge.&lt;br&gt;
Many production systems use both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I always need a vector database?&lt;/strong&gt;&lt;br&gt;
No.&lt;br&gt;
But vector databases are usually the most scalable solution for semantic retrieval.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can RAG work with PDFs?&lt;/strong&gt;&lt;br&gt;
Yes.&lt;br&gt;
PDFs are typically parsed, chunked, embedded, and stored in a vector database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is RAG only for chatbots?&lt;/strong&gt;&lt;br&gt;
Not at all.&lt;br&gt;
RAG powers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search engines&lt;/li&gt;
&lt;li&gt;Knowledge bases&lt;/li&gt;
&lt;li&gt;Recommendation systems&lt;/li&gt;
&lt;li&gt;Enterprise assistants&lt;/li&gt;
&lt;li&gt;Learning platforms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Does RAG eliminate hallucinations?&lt;/strong&gt;&lt;br&gt;
No.&lt;br&gt;
But it significantly reduces them by grounding responses in actual information.&lt;/p&gt;

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

&lt;p&gt;One of the biggest lessons from the first wave of AI applications is that language models alone are rarely enough.&lt;/p&gt;

&lt;p&gt;Businesses need systems that can access current information, understand private knowledge, and provide answers grounded in real data.&lt;/p&gt;

&lt;p&gt;That's exactly what RAG and Vector Databases make possible.&lt;br&gt;
By combining retrieval with generation, developers can build AI applications that are more accurate, easier to maintain, and far more useful in real-world environments.&lt;/p&gt;

&lt;p&gt;If you're building modern AI products today, understanding RAG is no longer optional.&lt;/p&gt;

&lt;p&gt;It's quickly becoming a foundational skill for AI engineers, backend developers, and architects alike&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Without data, you're just another person with an opinion.” - W. Edwards Deming&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;About the Author:&lt;em&gt;Ankit is a full-stack developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt; and AI enthusiast who crafts intelligent web solutions with PHP, Laravel, and modern frontend tools.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rag</category>
      <category>vectordatabases</category>
      <category>ai</category>
      <category>semanticsearch</category>
    </item>
    <item>
      <title>Passwordless Authentication with Passkeys</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Fri, 26 Jun 2026 12:02:29 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/passwordless-authentication-with-passkeys-1h1f</link>
      <guid>https://dev.to/addwebsolutionpvtltd/passwordless-authentication-with-passkeys-1h1f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“The best password is the one users never have to remember”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Passkeys eliminate traditional passwords.&lt;/li&gt;
&lt;li&gt;Built on FIDO2 and WebAuthn standards.&lt;/li&gt;
&lt;li&gt;Resistant to phishing attacks.&lt;/li&gt;
&lt;li&gt;Provide better security and user experience.&lt;/li&gt;
&lt;li&gt;Work across devices through secure synchronization.&lt;/li&gt;
&lt;li&gt;Reduce account recovery and password reset costs.&lt;/li&gt;
&lt;li&gt;Supported by Apple, Google, Microsoft, and major browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;For decades, usernames and passwords have been the primary method of authentication.&lt;/p&gt;

&lt;p&gt;However, passwords introduce major security and usability challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Weak passwords&lt;/li&gt;
&lt;li&gt;Password reuse&lt;/li&gt;
&lt;li&gt;Credential stuffing attacks&lt;/li&gt;
&lt;li&gt;Phishing attacks&lt;/li&gt;
&lt;li&gt;Password database breaches&lt;/li&gt;
&lt;li&gt;Costly password reset flows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As cyber threats continue to evolve, the industry is moving toward passwordless authentication. One of the most promising solutions is Passkeys.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What password does the user know?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Passkeys ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Can the user's trusted device prove their identity cryptographically?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This shift dramatically improves both security and user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What Are Passkeys?&lt;/li&gt;
&lt;li&gt;Why Passwords Are Failing&lt;/li&gt;
&lt;li&gt;How Passkeys Work&lt;/li&gt;
&lt;li&gt;Core Components&lt;/li&gt;
&lt;li&gt;Passkeys vs Passwords&lt;/li&gt;
&lt;li&gt;Passkeys Architecture&lt;/li&gt;
&lt;li&gt;Registration Flow&lt;/li&gt;
&lt;li&gt;Authentication Flow&lt;/li&gt;
&lt;li&gt;Backend Implementation Example&lt;/li&gt;
&lt;li&gt;Security Benefits&lt;/li&gt;
&lt;li&gt;Enterprise Adoption&lt;/li&gt;
&lt;li&gt;Challenges &amp;amp; Considerations&lt;/li&gt;
&lt;li&gt;Best Practices&lt;/li&gt;
&lt;li&gt;Real-World Example&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;Stats&lt;/li&gt;
&lt;li&gt;FAQs&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Are Passkeys?
&lt;/h2&gt;

&lt;p&gt;A passkey is a cryptographic credential that replaces passwords.&lt;br&gt;
A passkey consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public Key&lt;/li&gt;
&lt;li&gt;Private Key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The private key remains securely stored on the user's device and never leaves it.&lt;/p&gt;

&lt;p&gt;The public key is stored by the application server.&lt;/p&gt;

&lt;p&gt;When authentication occurs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server sends a challenge&lt;/li&gt;
&lt;li&gt;Device signs challenge using private key&lt;/li&gt;
&lt;li&gt;Server verifies signature using public key
No password transmission occurs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Why Passwords Are Failing
&lt;/h2&gt;

&lt;p&gt;Traditional passwords suffer from several issues:&lt;br&gt;
&lt;strong&gt;Security Problems&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Password reuse&lt;/li&gt;
&lt;li&gt;Brute force attacks&lt;/li&gt;
&lt;li&gt;Credential stuffing&lt;/li&gt;
&lt;li&gt;Phishing scams&lt;/li&gt;
&lt;li&gt;Database leaks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;User Experience Problems&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forgotten passwords&lt;/li&gt;
&lt;li&gt;Complex password rules&lt;/li&gt;
&lt;li&gt;Frequent resets&lt;/li&gt;
&lt;li&gt;Multiple account management
According to industry reports, compromised credentials remain one of the most common causes of security breaches.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How Passkeys Work
&lt;/h2&gt;

&lt;p&gt;Passkeys rely on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WebAuthn&lt;/li&gt;
&lt;li&gt;FIDO2&lt;/li&gt;
&lt;li&gt;Public Key Cryptography&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;High-Level Flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Device
 ↓
Generate Key Pair
 ↓
Private Key → Stored Securely
Public Key → Stored by Server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Authentication:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server Challenge
 ↓
Device Signs Challenge
 ↓
Server Verifies Signature
 ↓
Access Granted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server never stores sensitive secrets that can be stolen and reused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. User Device&lt;/strong&gt;&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;iPhone&lt;/li&gt;
&lt;li&gt;Android Device&lt;/li&gt;
&lt;li&gt;MacBook&lt;/li&gt;
&lt;li&gt;Windows PC
Stores the private key securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Authenticator&lt;/strong&gt;&lt;br&gt;
Responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Biometric verification&lt;/li&gt;
&lt;li&gt;Key generation&lt;/li&gt;
&lt;li&gt;Challenge signing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Face ID&lt;/li&gt;
&lt;li&gt;Touch ID&lt;/li&gt;
&lt;li&gt;Windows Hello&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Relying Party (Application)&lt;/strong&gt;&lt;br&gt;
The application requesting authentication.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Banking App&lt;/li&gt;
&lt;li&gt;SaaS Platform&lt;/li&gt;
&lt;li&gt;E-commerce Website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Authentication Server&lt;/strong&gt;&lt;br&gt;
Stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public keys&lt;/li&gt;
&lt;li&gt;Credential IDs&lt;/li&gt;
&lt;li&gt;User metadata&lt;/li&gt;
&lt;li&gt;Verifies cryptographic signatures.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Passkeys vs Passwords
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcv64gdddz3vlkhjecnqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcv64gdddz3vlkhjecnqo.png" alt=" " width="631" height="425"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Passkeys Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Recommended Architecture&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client Device
 ↓
Browser (WebAuthn)
 ↓
Authentication API
 ↓
Passkey Service
 ↓
Credential Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Components:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser&lt;/li&gt;
&lt;li&gt;Authenticator&lt;/li&gt;
&lt;li&gt;Backend API&lt;/li&gt;
&lt;li&gt;Credential Store&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Registration Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User creates account
 ↓
Server generates challenge
 ↓
Browser invokes WebAuthn
 ↓
Authenticator creates key pair
 ↓
Public key sent to server
 ↓
Server stores credential
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Endpoint : POST /register/passkey&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"challenge"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"randomChallenge"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"rpId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"example.com"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Authentication Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User clicks "Sign In"
 ↓
Server generates challenge
 ↓
Authenticator verifies user
 ↓
Challenge signed
 ↓
Signature sent to server
 ↓
Server validates signature
 ↓
User authenticated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Endpoint : POST /login/passkey&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"credentialId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"signature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"clientDataJSON"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Backend Implementation Example
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Node.js Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;generateAuthenticationOptions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@simplewebauthn/server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nf"&gt;generateAuthenticationOptions&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
     &lt;span class="na"&gt;rpID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;verification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
 &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;verifyAuthenticationResponse&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;expectedChallenge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;expectedOrigin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;expectedRPID&lt;/span&gt;
 &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verified&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// Login user&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Security Benefits
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Phishing Resistance&lt;/strong&gt;&lt;br&gt;
Users cannot accidentally reveal a passkey.&lt;br&gt;
The credential works only for the legitimate domain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. No Shared Secrets&lt;/strong&gt;&lt;br&gt;
Servers store public keys only.&lt;br&gt;
Database leaks become significantly less damaging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Strong Cryptography&lt;/strong&gt;&lt;br&gt;
Uses modern asymmetric cryptography rather than user-generated passwords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Built-in MFA&lt;/strong&gt;&lt;br&gt;
Something you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Device&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Something you are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Face ID&lt;/li&gt;
&lt;li&gt;Fingerprint&lt;/li&gt;
&lt;li&gt;This provides MFA-like protection without additional friction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Enterprise Adoption
&lt;/h2&gt;

&lt;p&gt;Major technology companies have already embraced passkeys.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apple&lt;/li&gt;
&lt;li&gt;Google&lt;/li&gt;
&lt;li&gt;Microsoft&lt;/li&gt;
&lt;li&gt;Amazon&lt;/li&gt;
&lt;li&gt;GitHub&lt;/li&gt;
&lt;li&gt;Shopify
Many enterprise identity providers now support passkey-based authentication.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges &amp;amp; Considerations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Device Recovery&lt;/strong&gt;&lt;br&gt;
Users may lose devices.&lt;/p&gt;

&lt;p&gt;Recommended:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passkey synchronization&lt;/li&gt;
&lt;li&gt;Recovery methods&lt;/li&gt;
&lt;li&gt;Secondary authenticators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Legacy Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Older applications may require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hybrid authentication&lt;/li&gt;
&lt;li&gt;Password fallback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;User Education&lt;/strong&gt;&lt;br&gt;
Many users are unfamiliar with passkeys.&lt;br&gt;
Clear onboarding is essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Support Multiple Authenticators&lt;/strong&gt;&lt;br&gt;
Allow users to register multiple devices.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Phone&lt;/li&gt;
&lt;li&gt;Laptop&lt;/li&gt;
&lt;li&gt;Security Key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Maintain Recovery Flow&lt;/strong&gt;&lt;br&gt;
Always provide secure account recovery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Use Trusted Standards&lt;/strong&gt;&lt;br&gt;
Prefer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WebAuthn&lt;/li&gt;
&lt;li&gt;FIDO2
Avoid custom cryptographic implementations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Log Authentication Events&lt;/strong&gt;&lt;br&gt;
Track:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Device registrations&lt;/li&gt;
&lt;li&gt;Authentication attempts&lt;/li&gt;
&lt;li&gt;Credential removals&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Example (SaaS Platform)
&lt;/h2&gt;

&lt;p&gt;Scenario:&lt;br&gt;
A project management platform wants passwordless login.&lt;br&gt;
Registration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User signs up&lt;/li&gt;
&lt;li&gt;Creates passkey&lt;/li&gt;
&lt;li&gt;Public key stored
Login:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;User enters email&lt;/li&gt;
&lt;li&gt;Device prompts Face ID&lt;/li&gt;
&lt;li&gt;Signature generated&lt;/li&gt;
&lt;li&gt;Server verifies&lt;/li&gt;
&lt;li&gt;User logged in
No password required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Passkeys are based on the FIDO2 and WebAuthn standards developed by the &lt;a href="https://fidoalliance.org/passkeys" rel="noopener noreferrer"&gt;FIDO Alliance&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Private keys never leave the user's device, making passkeys highly resistant to credential theft.&lt;/li&gt;
&lt;li&gt;Major technology companies including &lt;a href="https://developer.apple.com/passkeys" rel="noopener noreferrer"&gt;Apple Passkeys&lt;/a&gt;, &lt;a href="https://developers.google.com/identity/passkeys" rel="noopener noreferrer"&gt;Google Passkeys&lt;/a&gt;, and &lt;a href="https://learn.microsoft.com/en-us/windows/security/identity-protection/passkeys" rel="noopener noreferrer"&gt;Microsoft Passkeys&lt;/a&gt; support passkey authentication.&lt;/li&gt;
&lt;li&gt;Passkeys automatically protect users against phishing because credentials are bound to the legitimate website domain.&lt;/li&gt;
&lt;li&gt;The technology behind passkeys originated from the FIDO Alliance's mission to eliminate passwords entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;According to &lt;a href="https://www.verizon.com/business/resources/reports/dbir" rel="noopener noreferrer"&gt;Verizon Data Breach Investigations Report (DBIR)&lt;/a&gt;, compromised credentials remain one of the most common causes of data breaches.&lt;/li&gt;
&lt;li&gt;Microsoft Security Research reports that password-based attacks continue to be one of the largest attack vectors on user accounts.&lt;/li&gt;
&lt;li&gt;According to the &lt;a href="https://fidoalliance.org/passkeys" rel="noopener noreferrer"&gt;FIDO Alliance Passkey Research&lt;/a&gt;, users experience faster sign-ins and significantly lower account recovery requirements when using passkeys.&lt;/li&gt;
&lt;li&gt;Organizations adopting passwordless authentication often report reduced helpdesk costs related to password resets and account lockouts.&lt;/li&gt;
&lt;li&gt;Passkeys can dramatically reduce the success rate of phishing and credential-stuffing attacks because no reusable secret is transmitted or stored on the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q1. Are passkeys more secure than passwords?&lt;/strong&gt;&lt;br&gt;
Yes. They eliminate phishing, password reuse, and credential stuffing risks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q2. Can passkeys replace MFA?&lt;/strong&gt;&lt;br&gt;
In many cases, yes. Passkeys combine device possession and biometric verification.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3. What happens if I lose my device?&lt;/strong&gt;&lt;br&gt;
You can recover access using synced passkeys, backup devices, or account recovery methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q4. Do passkeys require biometrics?&lt;/strong&gt;&lt;br&gt;
No. Devices can also use PINs or other local authentication methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q5. Are passkeys supported by browsers?&lt;/strong&gt;&lt;br&gt;
Yes.&lt;br&gt;
Supported browsers include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome&lt;/li&gt;
&lt;li&gt;Safari&lt;/li&gt;
&lt;li&gt;Edge&lt;/li&gt;
&lt;li&gt;Firefox (partial support depending on platform)&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Passwords have served the internet for decades, but they introduce significant security and usability challenges.&lt;/p&gt;

&lt;p&gt;Passkeys represent the next evolution of authentication by replacing shared secrets with strong cryptographic credentials.&lt;/p&gt;

&lt;p&gt;By adopting passkeys, organizations can build authentication systems that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More secure&lt;/li&gt;
&lt;li&gt;Phishing resistant&lt;/li&gt;
&lt;li&gt;Easier to use&lt;/li&gt;
&lt;li&gt;Easier to scale&lt;/li&gt;
&lt;li&gt;Lower maintenance
As the industry continues moving toward passwordless authentication, passkeys are rapidly becoming the new standard for secure user identity verification.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;"Passwords prove what you know. Passkeys prove who you are through trusted cryptography."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;About the Author:&lt;em&gt;Mayank is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;, building scalable apps with PHP, Node.js &amp;amp; React. Sharing ideas, code, and creativity.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>authentication</category>
      <category>passkeys</category>
      <category>webauthn</category>
    </item>
    <item>
      <title>Prisma vs Drizzle ORM: A Comprehensive Comparison</title>
      <dc:creator>Lakashya Upadhyay</dc:creator>
      <pubDate>Tue, 23 Jun 2026 08:18:34 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/prisma-vs-drizzle-orm-a-comprehensive-comparison-3hc4</link>
      <guid>https://dev.to/addwebsolutionpvtltd/prisma-vs-drizzle-orm-a-comprehensive-comparison-3hc4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Your ORM should fit your project, not just your taste.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Practical Guide to Choosing Between Prisma and Drizzle ORM for Modern TypeScript Applications.&lt;/p&gt;

&lt;p&gt;In modern web applications, your ORM shapes how fast you can ship, how easy it is to maintain your data layer, and how clearly your team understands database behavior. Prisma and Drizzle ORM are both excellent TypeScript options, but they solve the problem in different ways: Prisma favors a higher-level, polished API, while Drizzle stays closer to SQL and gives you more explicit control.&lt;/p&gt;

&lt;p&gt;This guide explains the most important differences between Prisma and Drizzle ORM, when each one makes sense, and how to choose the right tool for your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Prisma offers a more abstracted, highly productive developer experience.&lt;/li&gt;
&lt;li&gt;Drizzle gives you SQL-like control with a thin TypeScript layer.&lt;/li&gt;
&lt;li&gt;Prisma is often a better fit for teams that want convention and speed of adoption.&lt;/li&gt;
&lt;li&gt;Drizzle is often a better fit for developers who prefer explicit queries and tighter SQL visibility.&lt;/li&gt;
&lt;li&gt;Both are production-ready, but the best choice depends on workflow, team preference, and performance needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why This Matters&lt;/li&gt;
&lt;li&gt;Choosing Based on the Wrong Criterion&lt;/li&gt;
&lt;li&gt;Prisma and Drizzle Are Not the Same&lt;/li&gt;
&lt;li&gt;Type Safety Differences&lt;/li&gt;
&lt;li&gt;Migrations and Schema Workflow&lt;/li&gt;
&lt;li&gt;Query Visibility and Performance&lt;/li&gt;
&lt;li&gt;Developer Experience vs Control&lt;/li&gt;
&lt;li&gt;Team Preferences&lt;/li&gt;
&lt;li&gt;Scaling Considerations&lt;/li&gt;
&lt;li&gt;Migration Strategy&lt;/li&gt;
&lt;li&gt;Frequently Asked Questions (FAQs)&lt;/li&gt;
&lt;li&gt;Interesting Facts &amp;amp; Stats&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Choosing an ORM is not just a syntax preference. It affects how your database layer is structured, how easily your team can refactor code, and how much visibility you have into the queries your app is actually running.&lt;/p&gt;

&lt;p&gt;Prisma is built around a convenient and expressive API, while Drizzle is designed as a thin wrapper around SQL-like syntax. That difference matters when you care about onboarding, code style consistency, query tuning, or long-term maintainability.&lt;/p&gt;

&lt;p&gt;This becomes especially important in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Startup MVPs.&lt;/li&gt;
&lt;li&gt;API-heavy backends.&lt;/li&gt;
&lt;li&gt;Multi-developer teams.&lt;/li&gt;
&lt;li&gt;Applications with frequent schema changes.&lt;/li&gt;
&lt;li&gt;Performance-sensitive systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good ORM choice helps your team move faster without losing clarity. A poor one can make migrations awkward, performance tuning harder, and code ownership more confusing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing Based on the Wrong Criterion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Don’t pick an ORM because it’s trending.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A common mistake is choosing Prisma or Drizzle based only on community hype, tutorial availability, or what a colleague used in a different project.&lt;br&gt;
How to think about it:&lt;br&gt;
Choose Prisma if you want strong abstraction, a mature ecosystem, and a guided developer experience.&lt;br&gt;
Choose Drizzle if you want explicit SQL control, a lightweight runtime approach, and closer visibility into queries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluate your team’s SQL comfort level.&lt;/li&gt;
&lt;li&gt;Decide how much abstraction you want.&lt;/li&gt;
&lt;li&gt;Consider how often your schema will change.&lt;/li&gt;
&lt;li&gt;Think about performance and deployment environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better tool alignment.&lt;/li&gt;
&lt;li&gt;Fewer rewrites later.&lt;/li&gt;
&lt;li&gt;Cleaner onboarding for your team.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Prisma and Drizzle Are Not the Same
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Similar goals do not mean the same workflow.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prisma and Drizzle both help TypeScript apps talk to databases, but their philosophies differ significantly. Prisma uses a more expressive API and schema-driven workflow, while Drizzle emphasizes SQL-like syntax and direct query composition.&lt;br&gt;
Example difference:&lt;br&gt;
Prisma style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drizzle style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand the mental model before adopting either tool.&lt;/li&gt;
&lt;li&gt;Use Prisma when you want a guided abstraction.&lt;/li&gt;
&lt;li&gt;Use Drizzle when you want closer control over query shape.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner code decisions.&lt;/li&gt;
&lt;li&gt;Fewer architectural surprises.&lt;/li&gt;
&lt;li&gt;More predictable development flow.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Type Safety Differences
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Both are type-safe, but they get there differently.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prisma is widely known for its generated client and strong autocomplete experience, while Drizzle emphasizes TypeScript-first query building with SQL-like clarity. The type safety is real in both tools, but the ergonomics are different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask whether your team prefers:&lt;/li&gt;
&lt;li&gt;Generated client types and model-centric APIs.&lt;/li&gt;
&lt;li&gt;Or explicit schema-driven queries with minimal abstraction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prisma strengths:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strong generated types.&lt;/li&gt;
&lt;li&gt;Very polished developer tooling.&lt;/li&gt;
&lt;li&gt;Clear model-based access patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drizzle strengths:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type inference close to SQL.&lt;/li&gt;
&lt;li&gt;Less hidden behavior.&lt;/li&gt;
&lt;li&gt;Readable query composition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;br&gt;
Safer database access,Fewer runtime mistakes and Better editor support.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrations and Schema Workflow
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Your migration workflow may matter more than the query API.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prisma and Drizzle differ in how they approach schema management and migrations. Prisma is often chosen for its schema-first workflow and convenient tooling, while Drizzle is favored by developers who want a more SQL-like, explicit workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose based on how your team handles schema changes.&lt;/li&gt;
&lt;li&gt;Decide whether you want generated migrations or closer control.&lt;/li&gt;
&lt;li&gt;Consider how often multiple developers will touch the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prisma is often preferred when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want a central schema file.&lt;/li&gt;
&lt;li&gt;You want a guided migration experience.&lt;/li&gt;
&lt;li&gt;You value a mature ecosystem.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drizzle is often preferred when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want more direct control over SQL output.&lt;/li&gt;
&lt;li&gt;You want minimal abstraction.&lt;/li&gt;
&lt;li&gt;You prefer handwritten or closely managed schema logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Safer schema changes,Cleaner deployment flow and Less migration confusion.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Query Visibility and Performance
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Fast code is not always obvious code.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the biggest practical differences is how easy it is to understand the SQL being executed. Drizzle is intentionally close to SQL and designed as a thin layer, while Prisma leans more toward abstraction. That can make Drizzle feel easier to reason about when performance matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Profile real queries early.&lt;/li&gt;
&lt;li&gt;Inspect what your ORM is generating.&lt;/li&gt;
&lt;li&gt;Avoid over-fetching data.&lt;/li&gt;
&lt;li&gt;Paginate large result sets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prisma considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very productive for day-to-day development.&lt;/li&gt;
&lt;li&gt;Nested relation handling can be convenient.&lt;/li&gt;
&lt;li&gt;You may need to be more careful when query complexity grows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drizzle considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More direct SQL visibility.&lt;/li&gt;
&lt;li&gt;Often easier to reason about exact query shape.&lt;/li&gt;
&lt;li&gt;A better fit for teams that want explicit control.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better performance awareness,Less hidden query cost and More predictable production behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Developer Experience vs Control
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“A polished API is not the same as total control.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prisma is often favored for developer experience, while Drizzle is often favored for control and minimal runtime overhead. That does not make one universally better. It just means they serve different priorities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose Prisma if your team values:&lt;/li&gt;
&lt;li&gt;Speed of development.&lt;/li&gt;
&lt;li&gt;A mature, guided ecosystem.&lt;/li&gt;
&lt;li&gt;Less time spent shaping queries manually.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Choose Drizzle if your team values:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL familiarity.&lt;/li&gt;
&lt;li&gt;Explicit query building.&lt;/li&gt;
&lt;li&gt;A lightweight ORM layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better match to your coding style,more consistent development habits and less friction during implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Team Preferences
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“The best ORM is the one your team can use consistently.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A small team with strong SQL experience may prefer Drizzle’s explicitness. A larger team with mixed skill levels may prefer Prisma’s higher-level structure and easier onboarding path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;br&gt;
Ask your team:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do we want abstraction or visibility?&lt;/li&gt;
&lt;li&gt;Do we prefer generated clients or explicit query building?&lt;/li&gt;
&lt;li&gt;How much SQL do we want developers to understand day to day?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prisma is often better for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convention-driven teams.&lt;/li&gt;
&lt;li&gt;Faster onboarding.&lt;/li&gt;
&lt;li&gt;Developer experience focused workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drizzle is often better for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL-fluent teams.&lt;/li&gt;
&lt;li&gt;Performance-aware backend work.&lt;/li&gt;
&lt;li&gt;Teams that want finer-grained query control.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better adoption,fewer style conflicts and more consistent code quality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Scaling Considerations
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Scaling means more than traffic.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When applications grow, the ORM choice starts affecting schema maintenance, query complexity, and how easily your team can tune the database layer. Drizzle’s benchmark page emphasizes its thin SQL layer and low runtime overhead, while Prisma emphasizes convenience and productivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;br&gt;
Think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schema size.&lt;/li&gt;
&lt;li&gt;Number of developers.&lt;/li&gt;
&lt;li&gt;Query complexity.&lt;/li&gt;
&lt;li&gt;Performance tuning expectations.&lt;/li&gt;
&lt;li&gt;Deployment environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prisma often works well for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast-moving products.&lt;/li&gt;
&lt;li&gt;Teams prioritizing productivity.&lt;/li&gt;
&lt;li&gt;Apps where abstraction helps more than raw control.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drizzle often works well for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database-heavy systems.&lt;/li&gt;
&lt;li&gt;Teams that want explicit query behavior.&lt;/li&gt;
&lt;li&gt;Projects where visibility and tuning matter more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better long-term architecture,improved maintainability and fewer scaling surprises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migration Strategy
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Switching ORM tools should be deliberate.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Moving from Prisma to Drizzle or the other way around can be useful, but it should not be done just because a trend changed. Since their APIs and workflows are different, a careless migration can create more work than value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document why you want the switch.&lt;/li&gt;
&lt;li&gt;Identify the parts of your app most affected.&lt;/li&gt;
&lt;li&gt;Migrate incrementally rather than all at once.&lt;/li&gt;
&lt;li&gt;Test queries and migrations carefully.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A good migration usually happens when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your current ORM no longer fits your performance needs.&lt;/li&gt;
&lt;li&gt;Your team needs more or less abstraction.&lt;/li&gt;
&lt;li&gt;Your workflow is becoming harder to maintain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lower rewrite risk,cleaner transition and less disruption for the team.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q. Is Prisma better than Drizzle ORM?&lt;/strong&gt;&lt;br&gt;
A. Not always. Prisma is often better for abstraction and productivity, while Drizzle is often better for SQL-like control and explicit query writing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Is Drizzle faster than Prisma?&lt;/strong&gt;&lt;br&gt;
A. Drizzle is designed as a thin layer on top of SQL and emphasizes low overhead, but real performance depends on your schema, queries, and indexes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Which ORM is easier for beginners?&lt;/strong&gt;&lt;br&gt;
A. Prisma is often easier for beginners because of its polished API and guided workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Which ORM is better for advanced SQL users?&lt;/strong&gt;&lt;br&gt;
A. Drizzle is often more appealing to SQL-fluent developers because it stays closer to query syntax and database behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q. Can I use either in production?&lt;/strong&gt;&lt;br&gt;
A. Yes. Both are used in real applications, and the right choice depends on your project and team.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interesting Facts &amp;amp; Stats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Prisma describes itself as focusing on a convenient and expressive API, while Drizzle positions itself as a thin wrapper around SQL-like syntax.Reference: &lt;a href="https://www.prisma.io/docs/orm/more/comparisons/prisma-and-drizzle" rel="noopener noreferrer"&gt;Prisma ORM vs Drizzle&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Drizzle’s benchmark page highlights low overhead and strong performance claims in production-like tests.Reference: &lt;a href="https://orm.drizzle.team/benchmarks" rel="noopener noreferrer"&gt;Benchmarks - Drizzle ORM&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Prisma is often favored for its mature ecosystem and polished developer experience.Reference: &lt;a href="https://makerkit.dev/blog/tutorials/drizzle-vs-prisma" rel="noopener noreferrer"&gt;Drizzle vs Prisma ORM in 2026: A Practical Comparison and Prisma ORM vs Drizzle&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Drizzle is often favored by developers who want direct SQL control and explicit query visibility.Reference: &lt;a href="https://www.bytebase.com/blog/drizzle-vs-prisma/" rel="noopener noreferrer"&gt;Drizzle ORM vs Prisma&lt;/a&gt; and &lt;a href="https://zenstack.dev/blog/drizzle-prisma" rel="noopener noreferrer"&gt;Drizzle or Prisma? I Built an App Twice to Find Out Which Is Better&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Many teams choose Prisma for speed of adoption and Drizzle for SQL-centric maintainability.Reference: &lt;a href="https://www.prisma.io/docs/orm/more/comparisons/prisma-and-drizzle" rel="noopener noreferrer"&gt;Prisma ORM vs Drizzle&lt;/a&gt; and &lt;a href="https://makerkit.dev/blog/tutorials/drizzle-vs-prisma" rel="noopener noreferrer"&gt;Drizzle vs Prisma ORM in 2026&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Prisma and Drizzle ORM both help TypeScript developers build safer database layers, but they are optimized for different priorities. Prisma gives you abstraction, productivity, and a polished workflow, while Drizzle gives you SQL-like control, lightweight behavior, and closer visibility into your queries.&lt;/p&gt;

&lt;p&gt;A strong choice usually comes down to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your team’s comfort with SQL.&lt;/li&gt;
&lt;li&gt;How much abstraction you want.&lt;/li&gt;
&lt;li&gt;How important performance visibility is.&lt;/li&gt;
&lt;li&gt;How you want to manage schema changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;About the Author: &lt;em&gt;Lakashya is a full‑stack Laravel developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWeb Solution&lt;/a&gt; specializing in scalable, real‑time applications with PHP and modern frontends.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>prisma</category>
      <category>drizzleorm</category>
      <category>typescript</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>The Complete API Security Checklist (A Defense-in-Depth Approach)</title>
      <dc:creator>Abodh Kumar</dc:creator>
      <pubDate>Mon, 22 Jun 2026 10:53:38 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/the-complete-api-security-checklist-a-defense-in-depth-approach-2pa</link>
      <guid>https://dev.to/addwebsolutionpvtltd/the-complete-api-security-checklist-a-defense-in-depth-approach-2pa</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;The only truly secure system is one that is powered off, cast in a block of concrete, and sealed in a lead-lined room with armed guards and even then I have my doubts.- GeneSpafford&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In any real-world API-driven system, the interface you expose is also the attack surface you inherit. Every endpoint that returns data, accepts input, or triggers an action is a potential entry point for an attacker. APIs are no longer a back-office concern - they are the front door to your data, your business logic, and your customers. How rigorously you secure them defines whether your platform is trusted or breached.&lt;/p&gt;

&lt;p&gt;Security is not a single feature you bolt on at the end; it is a series of controls layered at every level- identity, transport, data, traffic, and operations. A weakness in any one layer can undermine the others. This checklist walks through a complete, defense-in-depth strategy for securing APIs - from authentication and encryption through secrets management, the OWASP API Security Top 10, and incident response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaway
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Authenticate and authorize every request - verify both who the caller is and whether they may access this specific object, never one without the other.&lt;/li&gt;
&lt;li&gt;Enforce HTTPS/TLS everywhere and reject plaintext; encrypt sensitive data both in transit and at rest.&lt;/li&gt;
&lt;li&gt;Validate and sanitize all input against a strict allowlist schema - treat every payload, header, and query parameter as untrusted.&lt;/li&gt;
&lt;li&gt;Apply rate limiting and throttling on every endpoint to defend against brute force, scraping, and resource-exhaustion attacks.&lt;/li&gt;
&lt;li&gt;Never leak internal details in error responses, logs, or stack traces - return safe, generic messages to clients.&lt;/li&gt;
&lt;li&gt;Manage secrets and API keys in a dedicated vault, rotate them regularly, and keep them out of source control entirely.&lt;/li&gt;
&lt;li&gt;Map your controls to the OWASP API Security Top 10, scan continuously, and rehearse an incident response plan before you need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Understanding the OWASP API Security Top 10&lt;/li&gt;
&lt;li&gt;Authentication, Authorization &amp;amp; Access Control&lt;/li&gt;
&lt;li&gt;Encryption &amp;amp; Data Protection&lt;/li&gt;
&lt;li&gt;Managing Keys &amp;amp; Secrets&lt;/li&gt;
&lt;li&gt;Operational Security &amp;amp; Resilience&lt;/li&gt;
&lt;li&gt;Stats &amp;amp; Interesting Facts&lt;/li&gt;
&lt;li&gt;FAQ&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Modern software is assembled from APIs. Whether you are running a payments backend, a mobile app talking directly to microservices, a B2B integration exchanging records with partners, or an AI pipeline pulling from third-party services, APIs are the connective tissue that moves your most valuable data. That centrality is exactly what makes them attractive to attackers - a single unprotected endpoint can expose an entire database.&lt;/p&gt;

&lt;p&gt;The difference between a secure platform and a breached one rarely comes down to a single dramatic flaw. More often it is the accumulation of small omissions: an endpoint that checks authentication but forgets authorization, a forgotten staging API still serving production data, an error message that leaks a stack trace, an API key committed to a public repository. Attackers do not need to break your strongest control - they only need to find your weakest one.&lt;/p&gt;

&lt;p&gt;This article presents a complete, layered checklist for API security - covering identity and access control, transport and data encryption, input validation, key and secrets management, rate limiting, error handling, logging, security testing, versioning, and incident response. Each section pairs the why with concrete, production-ready code and configuration you can adapt directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Understanding the OWASP API Security Top 10
&lt;/h2&gt;

&lt;p&gt;Before writing a single control, anchor your security model to a shared threat framework. The OWASP API Security Top 10 (2023 edition) is the industry-standard list of the most critical API risks, distilled from real-world breach data. Read it less as a glossary and more as a checklist of questions to ask about your own endpoints. The ten risks fall naturally into three families.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.1 Broken Authorization (API1, API3, API5)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Three of the ten risks stem from the same mistake at different levels: failing to verify whether an authenticated caller is actually authorized to access a resource. Broken Object Level Authorization (API1, BOLA) is the most common and damaging API flaw, where a user changes an ID in the request and gains access to someone else's data. Broken Object Property Level Authorization (API3) covers excessive data exposure and mass assignment. - Returning or accepting fields the caller should never see or set. Broken Function Level Authorization (API5) is privilege escalation: a regular user reaching an admin-only operation. Authorization must be enforced on the server for every object and every action - never trust the client to scope its own access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//API1(BOLA)fix:verifyownershiponeveryobjectaccess&lt;/span&gt;
 &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/orders/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;constorder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;awaitOrder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nx"&gt;returnres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Notfound&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;//Thecriticalcheck:doesTHISuserownTHISobject?&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;returnres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Forbidden&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.2 Broken Authentication &amp;amp; Resource Abuse (API2, API4, API6)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Broken Authentication (API2) is the gateway to account takeover - weak password policies, missing brute-force protection, unverified tokens, or accepting credentials over insecure channels. Unrestricted Resource Consumption (API4) is the modern framing of denial-of-service and cost-amplification: endpoints with no rate limits, no payload size caps, and no pagination, allowing a single client to exhaust CPU, memory, bandwidth, or third-party billing. Unrestricted Access to Sensitive Business Flows (API6) targets workflows themselves - automating account creation, ticket purchases, or gift-card redemptions at a scale the business never intended, even when each individual request looks legitimate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.3 0Misconfiguration, SSRF &amp;amp; Inventory Risks (API7, API8, API9, API10)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final group covers the operational and configuration gaps that quietly widen your attack surface. Server-Side Request Forgery (API7) tricks your server into fetching an attacker-supplied URL - especially dangerous in cloud environments where it can pivot to internal metadata services. Security Misconfiguration (API8) spans verbose errors, missing security headers, permissive CORS, and unpatched components. Improper Inventory Management (API9) is the silent killer - undocumented "shadow" APIs, deprecated versions, and debug routes left running, exposing data through endpoints nobody is watching. Unsafe Consumption of APIs (API10) is trusting third-party responses without validation, a risk multiplied in AI pipelines that ingest external data blindly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Layeredmiddleware:authenticatefirst,thenauthorizebyrole&lt;/span&gt;
 &lt;span class="nf"&gt;functionauthenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="nx"&gt;constuser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;verifyToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nx"&gt;returnres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authentication required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nf"&gt;functionrequireRole&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
 &lt;span class="nx"&gt;returnres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Insufficientpermissions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/users/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;requireRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="nx"&gt;deleteUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;There are only two types of companies: those that have been hacked, and those that will be.- Robert Mueller&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Authentication, Authorization &amp;amp; Access Control
&lt;/h2&gt;

&lt;p&gt;Identity is the foundation of API security. Most catastrophic API breaches trace back to a failure here - either confirming the wrong identity or failing to constrain what a confirmed identity may do. Get this layer right and you eliminate the majority of the OWASP Top 10 in a single stroke.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.1 Authentication &amp;amp; Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Authentication answers "who is calling?"; authorization answers "what may they do?". They are distinct, and both must run on every protected request. Use strong, standardized mechanisms - never roll your own crypto or session logic. Enforce multi-factor authentication for sensitive operations, hash passwords with a slow algorithm such as bcrypt or Argon2, and lock out or back off after repeated failed attempts. For authorization, prefer explicit role- or attribute-based access control (RBAC/ABAC) checked server-side, and default to deny.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.2 Token Management - JWT &amp;amp; OAuth 2.0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tokens are bearer credentials: anyone holding a valid token is trusted, so their issuance, validation, and storage are critical. For JWTs, always verify the signature, pin the expected algorithm, and reject none and algorithm-confusion attacks. Validate the iss, aud, and exp claims.&lt;/p&gt;

&lt;p&gt;Keep access tokens short-lived and use rotating refresh tokens. For delegated access, use OAuth 2.0 with the appropriate grant type (Authorization Code with PKCE for public clients) and enforce least-privilege scopes on every endpoint.&lt;/p&gt;

&lt;p&gt;Store tokens in secure, HttpOnly cookies rather than local storage to limit XSS exposure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//VerifyaJWTstrictly:pinalgorithm,checkissuer+audience&lt;/span&gt;
 &lt;span class="nx"&gt;constjwt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="nf"&gt;functionverifyToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;authHeader&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="nx"&gt;consttoken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;authHeader&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bearer &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;returnjwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;JWT_PUBLIC_KEY&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
 &lt;span class="na"&gt;algorithms&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RS256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;//neveraccept'none'orHS/RSconfusion&lt;/span&gt;
 &lt;span class="na"&gt;issuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://auth.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;audience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="nx"&gt;returnnull&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//expired/tampered/wrongaudience&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.3 API Gateway, Versioning &amp;amp; Access Control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An API gateway centralizes cross-cutting controls - authentication, rate limiting, schema validation, IP allowlisting, and request logging - so they are enforced consistently rather than reimplemented per service. Route all external traffic through it and never expose backend services directly.&lt;/p&gt;

&lt;p&gt;Just as important is inventory and versioning discipline (the antidote to OWASP API9): maintain a live catalog of every endpoint, version your API explicitly (e.g., /v1, /v2), publish a clear deprecation timeline with sunset headers, and decommission old versions on schedule.&lt;/p&gt;

&lt;p&gt;Shadow and zombie endpoints - deprecated routes still serving live data are among the most exploited blind spots.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Deprecation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sunset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wed,31Dec202523:59:59GMT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;https://api.example.com/v2&amp;gt;; rel="successor-version"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="nx"&gt;v1Router&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Encryption &amp;amp; Data Protection
&lt;/h2&gt;

&lt;p&gt;Even with perfect access control, data must be protected as it travels and as it rests. Encryption ensures that intercepted traffic and stolen storage are useless to an attacker, while strict input handling prevents the injection and tampering attacks that bypass your business logic entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.1 HTTPS/TLS Encryption&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every API call must travel over TLS - no exceptions, not even on internal networks. Enforce TLS&lt;br&gt;
1.2 as a minimum (prefer 1.3), disable legacy protocols and weak cipher suites, and redirect or reject all plaintext HTTP. Use HTTP Strict Transport Security (HSTS) to prevent protocol downgrade, keep certificates current with automated renewal, and consider mutual TLS (mTLS) for service-to-service and high-trust partner traffic. Add a baseline of security headers to every response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;consthelmet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;helmet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;helmet&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;hsts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;maxAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;31536000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;includeSubDomains&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;preload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="na"&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;span class="c1"&gt;//RejectanyrequestthatdidnotarriveoverHTTPS&lt;/span&gt;
 &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;secure&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;x-forwarded-proto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;returnnext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;HTTPS required&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
 &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.2 Input Validation &amp;amp; Sanitization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Treat every byte from the client as hostile - body, query string, path parameters, and headers alike. Validate against a strict allowlist schema that defines expected types, formats, lengths, and ranges, and reject anything that does not conform rather than trying to clean it. Use parameterized queries or an ORM to neutralize SQL injection, encode output to prevent XSS, and explicitly reject unexpected fields to block mass-assignment (OWASP API3). Schema-first validation libraries make this declarative and consistent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//AllowlistschemavalidationwithZod-rejectunknownfields&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="nx"&gt;constCreateUser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
 &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;254&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
 &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
 &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enum&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;editor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="c1"&gt;//'admin'canneverbeself-assigned&lt;/span&gt;
 &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;strict&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//throwsonanyextraproperty&lt;/span&gt;

 &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;constresult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CreateUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;returnres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;422&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Validationfailed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;details&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.3 Data Protection &amp;amp; Encryption at Rest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sensitive data - PII, credentials, payment details, health records - must be encrypted at rest, not just in transit. Use authenticated encryption such as AES-256-GCM for field-level protection of the most sensitive columns, and rely on full-disk or database-native encryption for the broader store. Apply data minimization: collect only what you need, return only the fields a client requires, and tokenize or mask data (for example, showing only the last four digits of a card) wherever the full value is not essential. Hash, never encrypt, values you only ever need to compare, such as passwords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Field-levelencryptionwithAES-256-GCM(authenticated)&lt;/span&gt;
&lt;span class="nx"&gt;constcrypto&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;crypto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;functionencrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plaintext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;constiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;constcipher&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createCipheriv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aes-256-gcm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;iv&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;constenc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;cipher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plaintext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="nx"&gt;cipher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;final&lt;/span&gt;&lt;span class="p"&gt;()]);&lt;/span&gt;&lt;span class="nx"&gt;consttag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cipher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAuthTag&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// detects tampering on decryptreturnBuffer.concat([iv, tag, enc]).toString('base64');&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Managing Keys &amp;amp; Secrets
&lt;/h2&gt;

&lt;p&gt;Credentials are the keys to the kingdom, and they leak constantly - committed to repositories, baked into mobile binaries, logged in plaintext, or shared in chat. A single exposed secret can unravel every other control you have built. Treat keys and secrets as first-class assets with their own lifecycle of issuance, storage, rotation, and revocation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.1 API Key Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;API keys identify and meter callers, but they are weak as a sole authentication factor - pair them with tokens or mTLS for anything sensitive. Never store keys in plaintext: persist only a salted hash, just as you would a password, so a database leak does not expose usable credentials. Scope each key to the minimum permissions and resources it needs, bind keys to specific clients or IP ranges where practical, support instant revocation, and rotate them on a defined schedule. Surface the key to the user exactly once at creation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Generateonce,returnonce,storeonlythehash&lt;/span&gt;
&lt;span class="nx"&gt;constcrypto&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;crypto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;functionissueApiKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="nx"&gt;constrawKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sk_&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;consthash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sha256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rawKey&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apiKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="na"&gt;revoked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;span class="nx"&gt;returnrawKey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// shown to the user only at this moment - never recoverable later&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.2 Secrets Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Database passwords, signing keys, third-party tokens, and certificates must never live in source control, hardcoded constants, or unencrypted config files. Use a dedicated secrets manager - HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, or your platform's equivalent - to store, access-control, and audit them, and inject them at runtime via environment variables or short-lived dynamic credentials. Enable automatic rotation, scan every commit and CI pipeline for accidentally leaked secrets, and immediately revoke and rotate anything that is exposed. The prevalence of secret-leak breaches makes this non-negotiable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Loadsecretsatruntimefromamanager-neverfromthecodebase&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;SecretsManagerClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;GetSecretValueCommand&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@aws-sdk/client-secrets-manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;asyncfunctiongetSecret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="nx"&gt;constclient&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;newSecretsManagerClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;us-east-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;constres&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;awaitclient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;newGetSecretValueCommand&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;SecretId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;&lt;span class="nx"&gt;returnJSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SecretString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//.gitignoremustinclude.env-addsecretscanning(gitleaks)toCI&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Operational Security &amp;amp; Resilience
&lt;/h2&gt;

&lt;p&gt;Security does not end at deployment. Running APIs need continuous protection against abuse, careful handling of failures, vigilant observability, ongoing testing, and a plan for when something goes wrong. This is the layer that keeps you secure over time, not just on launch day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.1 Rate Limiting &amp;amp; Throttling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rate limiting is your primary defense against brute-force login attempts, credential stuffing, scraping, and resource-exhaustion attacks (OWASP API4). Apply limits per client, per IP, and per endpoint - authentication routes warrant far stricter limits than read-only public ones.&lt;/p&gt;

&lt;p&gt;Use a token-bucket or sliding-window algorithm, return 429 Too Many Requests with a Retry-After header, and back limits with a shared store like Redis so they hold across multiple instances. Pair rate limiting with payload size caps and mandatory pagination.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Strictlimitonauthendpoints;backedbyRedisformulti-instance&lt;/span&gt;
&lt;span class="nx"&gt;constrateLimit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express-rate-limit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;constloginLimiter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;rateLimit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="na"&gt;windowMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;//15minutes&lt;/span&gt;
&lt;span class="na"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;//5attemptsperwindowperIP&lt;/span&gt;
&lt;span class="na"&gt;standardHeaders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Toomanyattempts.Tryagainlater.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/auth/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;loginLimiter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;login&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.2 Error Handling &amp;amp; Information Disclosure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Error responses are a classic information leak. A raw stack trace, database error, or internal path tells an attacker exactly how your system is built and where it is vulnerable. Return generic, safe messages to clients while logging the full detail internally for your own diagnostics. Use correct HTTP status codes, never echo back internal exceptions, and for validation errors (422) provide&lt;br&gt;
precise field-level feedback without exposing implementation specifics. A centralized error handler keeps this consistent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Centralizedhandler:detailedlogsinternally,saferesponseexternally&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;reqId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;conststatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;An internal error occurred.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publicMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// correlate with logs without leaking internals&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.3 Logging, Monitoring &amp;amp; Security Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You cannot defend what you cannot see. Emit structured, centralized logs for authentication events, authorization failures, rate-limit hits, and anomalous patterns - while scrupulously redacting secrets, tokens, and PII from log output. Feed logs into monitoring and alerting so suspicious behavior (a spike in 401s, unusual data volumes, access from new geographies) triggers a response. Equally important is testing before attackers do: integrate SAST, DAST, dependency/CVE scanning, and OWASP-mapped API security tests directly into CI/CD, and gate deployments on critical findings. Conduct regular penetration tests and fuzzing against your real schemas.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Structuredauditlogwithredaction-neverlograwtokensorPII&lt;/span&gt;
&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;auth.login.failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;unknown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;invalid_password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="c1"&gt;//password,tokenandfullheadersaredeliberatelyomitted&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;//CIgate(pseudo):runDASTmappedtoOWASPAPITop10,failonCritical&lt;/span&gt;
&lt;span class="c1"&gt;//  $api-scan--specopenapi.yaml--rulesetowasp-api-top10--fail-oncritical&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.4 Backup &amp;amp; Incident Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Assume that, eventually, something will fail or be breached - and prepare for it. Maintain encrypted, regularly tested backups stored separately from production, with immutable or versioned copies to survive ransomware. Just as critical is a written incident response plan: defined roles, escalation paths, and runbooks for containment (revoking tokens and keys, isolating endpoints), eradication, recovery, and post-incident review. Rehearse it - a plan first read during a live breach is worth little. Define your breach-notification obligations in advance so you can meet legal and contractual deadlines under pressure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Rapidcontainment:mass-revokeacompromisedclient'scredentials&lt;/span&gt;
&lt;span class="nf"&gt;asyncfunctioncontainBreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="nx"&gt;awaitdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apiKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateMany&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;},{&lt;/span&gt;&lt;span class="na"&gt;revoked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;awaittokenStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revokeAllForClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sessionsawaitrotateSecrets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;secretsalerting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;security-oncall&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;breach-containment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Amateurs hack systems, professionals hack people - and increasingly, both hack APIs.- Adapted from Bruce Schneier&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  7. Stats &amp;amp; Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Salt Security's 2024 State of API Security report found that 95% of organizations experienced security problems in their production APIs, and 23% suffered an actual breach - yet only 7.5% had a dedicated API testing and threat-modeling program in place. Source: &lt;a href="https://salt.security/blog/its-2024-and-the-api-breaches-keep-coming" rel="noopener noreferrer"&gt;https://salt.security/blog/its-2024-and-the-api-breaches-keep-coming&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;According to Gartner's Market Guide for API Protection (cited by Akamai), the average API breach leaks at least 10 times more data than the average security breach - APIs expose data at scale. Source: &lt;a href="https://www.akamai.com/newsroom/press-release/new-study-finds-84-of-security-professionals-experienced-an-api-security-incident-in-the-past-year" rel="noopener noreferrer"&gt;https://www.akamai.com/newsroom/press-release/new-study-finds-84-of-security-professionals-experienced-an-api-security-incident-in-the-past-year&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;An Akamai study reported that 84% of security professionals experienced an API security incident in the past year, while the share of organizations maintaining a full API inventory fell from 40% in 2023 to just 27% in 2024 - meaning most teams cannot see their own attack surface. Source: &lt;a href="https://www.akamai.com/newsroom/press-release/new-study-finds-84-of-security-professionals-experienced-an-api-security-incident-in-the-past-year" rel="noopener noreferrer"&gt;https://www.akamai.com/newsroom/press-release/new-study-finds-84-of-security-professionals-experienced-an-api-security-incident-in-the-past-year&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Imperva's State of API Security report found that account-takeover attacks targeting APIs climbed from 35% in 2022 to 46% in 2023, and that 46% of all account-takeover attacks were aimed at API endpoints. Source: &lt;a href="https://www.imperva.com/blog/state-of-api-security-in-2024/" rel="noopener noreferrer"&gt;https://www.imperva.com/blog/state-of-api-security-in-2024/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A large share of real-world attacks map directly to the OWASP API Security Top 10 - Salt Security found that roughly 78% of attack attempts leveraged one or more of those Top 10 categories, with Broken Object Level Authorization (BOLA) alone accounting for a large fraction of API attacks. Source: &lt;a href="https://salt.security/api-security-trends" rel="noopener noreferrer"&gt;https://salt.security/api-security-trends&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cloudflare's 2024 API security report found that APIs now make up well over half of all Internet traffic (around 57%), dramatically expanding the surface that must be secured and managed. Source: &lt;a href="https://www.cloudflare.com/2024-api-security-management-report/" rel="noopener noreferrer"&gt;https://www.cloudflare.com/2024-api-security-management-report/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Secret sprawl is a leading breach vector: researchers reported that nearly 13 million API secrets and credentials were exposed through public GitHub repositories in a single year, handing attackers ready-made keys. Source: &lt;a href="https://salt.security/blog/its-2024-and-the-api-breaches-keep-coming" rel="noopener noreferrer"&gt;https://salt.security/blog/its-2024-and-the-api-breaches-keep-coming&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.What is the difference between authentication and authorization, and why do I need both?&lt;/strong&gt;&lt;br&gt;
Ans: Authentication verifies who the caller is; authorization verifies what they are allowed to do. They are independent checks, and the most common serious API flaw - Broken Object Level&lt;br&gt;
Authorization - happens when an endpoint authenticates the user but never confirms they own the specific resource they requested. Always enforce both, on every protected request, on the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Are API keys enough to secure an API on their own?&lt;/strong&gt;&lt;br&gt;
Ans: No. API keys are good for identifying and rate-limiting a caller, but they are static bearer credentials that are easily leaked and offer no built-in expiry or fine-grained scope. For anything sensitive, pair keys with short-lived tokens (OAuth 2.0 / JWT) or mutual TLS, store only hashed keys, scope them tightly, and rotate them regularly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. How should I handle validation errors (HTTP 422) without leaking information?&lt;/strong&gt;&lt;br&gt;
Ans: Return precise, field-level messages that tell the legitimate user exactly which input was invalid and why - but keep those messages about the input, never about your internal implementation. Never expose stack traces, database errors, or internal field names. Validate against a strict allowlist schema and reject unknown fields to also block mass-assignment attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Why is HTTPS necessary even for internal or service-to-service APIs?&lt;/strong&gt;&lt;br&gt;
Ans: Internal networks are not inherently trustworthy - once an attacker gains a foothold, unencrypted internal traffic is trivially intercepted, and lateral movement is exactly how breaches escalate. Enforce TLS everywhere, and use mutual TLS for service-to-service calls so both ends authenticate each other, not just the channel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What are "shadow APIs" and why are they so dangerous?&lt;/strong&gt;&lt;br&gt;
Ans: Shadow APIs are undocumented, forgotten, or deprecated endpoints still running in production - old versions, debug routes, or services left behind after a migration. They are dangerous precisely because no one is monitoring or patching them, yet they often still expose live data. This is OWASP API9 (Improper Inventory Management); the defense is a continuously updated API inventory, explicit versioning, and disciplined decommissioning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Should I build my own authentication and token logic?&lt;/strong&gt;&lt;br&gt;
Ans: Almost never. Authentication, session handling, and cryptography are full of subtle, exploitable pitfalls. Use battle-tested standards and libraries - OAuth 2.0, OpenID Connect, and established JWT libraries with strict verification - or a managed identity provider. Reserve your effort for correctly configuring and integrating them, especially algorithm pinning and claim validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7.How do I protect against denial-of-service and resource-exhaustion attacks?&lt;/strong&gt;&lt;br&gt;
Ans: Layer several controls: per-client and per-endpoint rate limiting, maximum payload sizes, mandatory pagination with capped page sizes, query complexity limits (especially for GraphQL), and timeouts on expensive operations. Place a gateway or WAF in front of your services, and use a &lt;br&gt;
shared store like Redis so limits hold across all instances. This addresses OWASP API4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. How do I protect against denial-of-service and resource-exhaustion attacks?&lt;/strong&gt;&lt;br&gt;
Ans: Layer several controls: per-client and per-endpoint rate limiting, maximum payload sizes, mandatory pagination with capped page sizes, query complexity limits (especially for GraphQL), and timeouts on expensive operations. Place a gateway or WAF in front of your services, and use a &lt;br&gt;
shared store like Redis so limits hold across all instances. This addresses OWASP API4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. How should I test my API's security before and after release?&lt;/strong&gt;&lt;br&gt;
Ans: Shift security left and keep it continuous. In CI/CD, run static analysis (SAST), dynamic scanning (DAST) mapped to the OWASP API Top 10, and dependency/CVE scanning, and gate deployments on critical findings. In production, run scheduled penetration tests, fuzz endpoints against your real OpenAPI schema, and monitor for anomalies. Secret scanning on every commit closes the most common leak path.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Conclusion
&lt;/h2&gt;

&lt;p&gt;Securing an API is not a single control but a series of overlapping layers, each compensating for the gaps in the others. No single measure is sufficient on its own - defense in depth is what turns a brittle system into a resilient one. Every layer described in this checklist plays a distinct role in a complete, attacker-aware strategy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identity and access control ensure every request is both authenticated and authorized down to the individual object - closing the most exploited class of API flaws.&lt;/li&gt;
&lt;li&gt;Encryption and strict input handling protect data in transit and at rest and neutralize injection, tampering, and mass-assignment attacks.&lt;/li&gt;
&lt;li&gt;Key and secrets management keep credentials hashed, vaulted, scoped, and rotated - out of source control and out of attackers' hands.&lt;/li&gt;
&lt;li&gt;Rate limiting, safe error handling, and least-privilege design add resilience against abuse and prevent the information leaks that fuel further attacks.&lt;/li&gt;
&lt;li&gt;Logging, monitoring, and continuous security testing give you visibility and early warning, mapping your controls to the OWASP API Security Top 10.&lt;/li&gt;
&lt;li&gt;Versioning discipline, encrypted backups, and a rehearsed incident response plan ensure you can recover quickly and contain damage when something does go wrong.&lt;/li&gt;
&lt;li&gt;The tools and standards you need already exist. The responsibility lies with engineering teams to compose them deliberately, verify them continuously, and treat security as a first-class requirement rather than a release-day afterthought. The best API security is invisible - an attacker who finds no exposed endpoint, no leaked secret, and no unchecked authorization simply moves on. That invisibility is the mark of a truly hardened API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;About the Author:&lt;em&gt;Abodh is a PHP and Laravel Developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWeb Solution&lt;/a&gt;, skilled in MySQL, REST APIs, JavaScript, Git, and Docker for building robust web applications.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>apisecurity</category>
      <category>cybersecurity</category>
      <category>owasp</category>
    </item>
    <item>
      <title>Master Tables vs EAV Architecture: Which One Should You Use?</title>
      <dc:creator>Vatsal Acharya</dc:creator>
      <pubDate>Tue, 16 Jun 2026 05:31:53 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/master-tables-vs-eav-architecture-which-one-should-you-use-521b</link>
      <guid>https://dev.to/addwebsolutionpvtltd/master-tables-vs-eav-architecture-which-one-should-you-use-521b</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;The structure of your data is every bit as important as the code that manipulates it. - Martin Fowler&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Master Tables provide strong structure, validation, and performance.&lt;/li&gt;
&lt;li&gt;EAV (Entity-Attribute-Value) offers flexibility for dynamic fields.&lt;/li&gt;
&lt;li&gt;Master Tables are easier to query and maintain.&lt;/li&gt;
&lt;li&gt;EAV is useful when attributes change frequently.&lt;/li&gt;
&lt;li&gt;Most enterprise applications use a hybrid approach rather than pure EAV.&lt;/li&gt;
&lt;li&gt;Choosing the wrong architecture can create long-term maintenance issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What Are Master Tables?&lt;/li&gt;
&lt;li&gt;Advantages of Master Tables&lt;/li&gt;
&lt;li&gt;Disadvantages of Master Tables&lt;/li&gt;
&lt;li&gt;What Is EAV Architecture?&lt;/li&gt;
&lt;li&gt;Advantages of EAV&lt;/li&gt;
&lt;li&gt;Disadvantages of EAV&lt;/li&gt;
&lt;li&gt;Real-World Example: College Management System&lt;/li&gt;
&lt;li&gt;Performance Comparison&lt;/li&gt;
&lt;li&gt;When Should You Use Master Tables?&lt;/li&gt;
&lt;li&gt;When Should You Use EAV?&lt;/li&gt;
&lt;li&gt;The Hybrid Approach (Recommended)&lt;/li&gt;
&lt;li&gt;Laravel Implementation Strategy&lt;/li&gt;
&lt;li&gt;Stats&lt;/li&gt;
&lt;li&gt;Frequently Asked Questions (FAQ)&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When building an admin panel or enterprise application, one common question arises:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Should I create dedicated master tables for every module, or should I use an EAV (Entity-Attribute-Value) architecture for maximum flexibility?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer depends on your business requirements, scalability goals, and how often your data structure changes.&lt;br&gt;
Let's explore both approaches.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Are Master Tables?
&lt;/h2&gt;

&lt;p&gt;Master Tables follow the traditional relational database design.&lt;br&gt;
Example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Colleges Table&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colleges
---------
id
name
email
phone
city
state
website
type
funding
created_at
updated_at
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Courses Table&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;courses
---------
id
college_id
name
duration
fees
created_at
updated_at
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every field has its own column.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Master Tables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Better Performance&lt;/strong&gt;&lt;br&gt;
Databases are optimized for column-based querying.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;colleges&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Gujarat'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fast and index-friendly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Strong Validation&lt;/strong&gt;&lt;br&gt;
Laravel validation becomes straightforward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
   &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="s1"&gt;'phone'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Easier Reporting&lt;/strong&gt;&lt;br&gt;
Generating reports is simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;colleges&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Easier Maintenance&lt;/strong&gt;&lt;br&gt;
New developers can understand the database quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Better Relationships&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;college
   ↳ courses
   ↳ faculty
   ↳ students
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Relationships remain clear and predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages of Master Tables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Schema Changes&lt;/strong&gt;&lt;br&gt;
Suppose a client suddenly wants:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAAC Grade
NIRF Ranking
Accreditation Year
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;colleges&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Frequent changes can become tedious.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is EAV Architecture?
&lt;/h2&gt;

&lt;p&gt;EAV stands for:&lt;br&gt;
&lt;strong&gt;Entity → Attribute → Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of storing attributes as columns, attributes become records.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Entity
college
---------
id
name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Attributes
attributes
---------
id
name
1  NAAC Grade
2  NIRF Ranking
3  Accreditation Year
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Values
entity_values
-------------
entity_id
attribute_id
value

1 | 1 | A++
1 | 2 | 15
1 | 3 | 2024
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now new fields can be added without changing database schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of EAV
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Dynamic Fields&lt;/strong&gt;&lt;br&gt;
Admin users can create fields themselves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add Field
---------
Field Name: Campus Size
Type: Number
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No migration required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Perfect for Form Builders&lt;/strong&gt;&lt;br&gt;
Useful in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LMS&lt;/li&gt;
&lt;li&gt;ERP&lt;/li&gt;
&lt;li&gt;CRM&lt;/li&gt;
&lt;li&gt;Survey Systems&lt;/li&gt;
&lt;li&gt;Dynamic Registration Forms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Unlimited Customization&lt;/strong&gt;&lt;br&gt;
Every organization can have different fields.&lt;br&gt;
Example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Organization A:&lt;/strong&gt;&lt;br&gt;
NAAC Grade&lt;br&gt;
NIRF Ranking&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Organization B:&lt;/strong&gt;&lt;br&gt;
Campus Size&lt;br&gt;
Hostel Capacity&lt;br&gt;
Same database structure.&lt;/p&gt;
&lt;h2&gt;
  
  
  Disadvantages of EAV
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Complex Queries&lt;/strong&gt;&lt;br&gt;
Finding colleges with NIRF ranking below 20:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;entity_values&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;attributes&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much harder than traditional SQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Poor Reporting Performance&lt;/strong&gt;&lt;br&gt;
Aggregations become expensive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;often require multiple joins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Difficult Validation&lt;/strong&gt;&lt;br&gt;
Validation rules become dynamic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'number'&lt;/span&gt;
&lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'date'&lt;/span&gt;
&lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More code complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Harder Debugging&lt;/strong&gt;&lt;br&gt;
Data is spread across multiple tables.&lt;br&gt;
Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;colleges&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may need several joins to understand a single record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Example
&lt;/h2&gt;

&lt;p&gt;Imagine building a College Management System.&lt;br&gt;
&lt;strong&gt;Using Master Tables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colleges
---------
name
email
phone
website
type
funding
city
state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good when fields are known.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using EAV&lt;/strong&gt;&lt;br&gt;
colleges&lt;/p&gt;

&lt;p&gt;attributes&lt;/p&gt;

&lt;p&gt;attribute_values&lt;br&gt;
Good when colleges can create custom fields.&lt;/p&gt;
&lt;h2&gt;
  
  
  Performance Comparison
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6y68vklbhgufoc6jkhgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6y68vklbhgufoc6jkhgy.png" alt=" " width="419" height="333"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  When Should You Use Master Tables?
&lt;/h2&gt;

&lt;p&gt;Choose Master Tables when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data structure is stable&lt;/li&gt;
&lt;li&gt;Reports are important&lt;/li&gt;
&lt;li&gt;Performance matters&lt;/li&gt;
&lt;li&gt;Relationships are well-defined&lt;/li&gt;
&lt;li&gt;ERP systems&lt;/li&gt;
&lt;li&gt;LMS systems&lt;/li&gt;
&lt;li&gt;E-commerce platforms&lt;/li&gt;
&lt;li&gt;Financial applications
This is the recommended approach for most business applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  When Should You Use EAV?
&lt;/h2&gt;

&lt;p&gt;Choose EAV when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users create custom fields&lt;/li&gt;
&lt;li&gt;Form structure changes frequently&lt;/li&gt;
&lt;li&gt;Different organizations require different attributes&lt;/li&gt;
&lt;li&gt;Building form builders&lt;/li&gt;
&lt;li&gt;Survey systems&lt;/li&gt;
&lt;li&gt;CRM custom fields&lt;/li&gt;
&lt;li&gt;Dynamic metadata systems&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Hybrid Approach (Recommended)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Bad programmers worry about the code. Good programmers worry about data structures and their relationships. - Linus Torvalds&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most modern systems combine both.&lt;br&gt;
Example:&lt;br&gt;
Master Table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colleges
---------
id
name
email
phone
city
state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Custom Fields (EAV)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;custom_fields

custom_field_values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Core fields stay in columns.&lt;br&gt;
Rarely used custom fields go into EAV.&lt;br&gt;
This gives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast queries&lt;/li&gt;
&lt;li&gt;Easy reporting&lt;/li&gt;
&lt;li&gt;Dynamic customization
without sacrificing performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Laravel Implementation Strategy
&lt;/h2&gt;

&lt;p&gt;A practical Laravel structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colleges
college_custom_fields
college_custom_field_values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;College
CollegeCustomField
CollegeCustomFieldValue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use EAV only for user-defined fields.&lt;br&gt;
Keep business-critical fields in normal columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stats
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;90%+ of the top databases in enterprise environments are relational databases. Source: &lt;a href="https://db-engines.com/en/ranking" rel="noopener noreferrer"&gt;DB-Engines Ranking&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;EAV is commonly found in healthcare, CRM, e-commerce, and form-builder systems where attributes change frequently.Source: &lt;a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC2110957/" rel="noopener noreferrer"&gt;NCBI EAV Research Paper&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Most high-scale business applications use a hybrid approach rather than pure EAV.Source: &lt;a href="https://martinfowler.com/eaaCatalog/metadataMapping.html" rel="noopener noreferrer"&gt;Martin Fowler Enterprise Application Architecture Resources&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQ)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Is EAV faster than traditional relational tables?&lt;/strong&gt;&lt;br&gt;
No. EAV is generally slower for querying and reporting because data is spread across multiple rows and tables, requiring additional joins and transformations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Why do ERP systems prefer master tables?&lt;/strong&gt;&lt;br&gt;
ERP systems usually handle structured business data such as customers, orders, invoices, and products. Master tables provide better performance, easier reporting, and stronger data integrity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. When should I choose EAV?&lt;/strong&gt;&lt;br&gt;
Choose EAV when users need to create custom fields dynamically and the data structure changes frequently without developer involvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Does Laravel support EAV architecture?&lt;/strong&gt;&lt;br&gt;
Laravel does not provide EAV out of the box, but it can be implemented using models such as CustomField and CustomFieldValue along with dynamic validation rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What architecture do large applications use?&lt;/strong&gt;&lt;br&gt;
Most large-scale applications use a hybrid approach, storing core business fields in relational tables while keeping optional or customizable attributes in EAV tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Is EAV a bad design pattern?&lt;/strong&gt;&lt;br&gt;
Not necessarily. EAV is powerful for highly dynamic data models, but it introduces complexity. It becomes problematic when used for data that could be stored efficiently in standard relational tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Which approach is best for a Laravel admin panel?&lt;/strong&gt;&lt;br&gt;
For most Laravel admin panels, master tables should be the default choice. Add EAV only for user-defined or customizable fields.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. What is the biggest mistake teams make?&lt;/strong&gt;&lt;br&gt;
Using EAV everywhere for future flexibility. This often leads to complex queries, slower reports, and maintenance challenges that outweigh the benefits.&lt;/p&gt;

&lt;p&gt;This structure makes the article feel more complete, professional, and optimized for Medium, Dev.to, Hashnode, and LinkedIn articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Most Relational Databases Are Optimized for Fixed Schemas&lt;/strong&gt;&lt;br&gt;
Traditional relational databases such as PostgreSQL and MySQL are designed around structured tables and indexed columns. This is one reason why well-designed master tables generally outperform EAV models for reporting and analytics workloads.Source: &lt;a href="https://www.postgresql.org/docs/current/indexes-intro.html" rel="noopener noreferrer"&gt;PostgreSQL Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. EAV Became Popular in Healthcare Systems&lt;/strong&gt;&lt;br&gt;
Many Electronic Health Record (EHR) systems adopted EAV because patient records can contain thousands of possible attributes, many of which apply only to specific patients. This made traditional schemas difficult to maintain.Source: &lt;a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC2110957/" rel="noopener noreferrer"&gt;National Center for Biotechnology Information (NCBI) Research on EAV Models&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;3. Magento Historically Used EAV Extensively&lt;/strong&gt;&lt;br&gt;
Magento became one of the most well-known large-scale applications using EAV for product attributes, allowing merchants to create custom product fields without altering database schemas.Source: &lt;a href="https://developer.adobe.com/commerce/php/development/components/attributes/" rel="noopener noreferrer"&gt;Adobe Commerce Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Most Enterprise Systems Use a Hybrid Model&lt;/strong&gt;&lt;br&gt;
Modern ERP, LMS, and CRM platforms typically store critical business data in relational tables while using flexible metadata tables for custom fields, effectively combining Master Tables and EAV concepts.&lt;br&gt;
Source: &lt;a href="https://martinfowler.com/eaaCatalog/metadataMapping.html" rel="noopener noreferrer"&gt;Martin Fowler - Metadata Mapping Pattern&lt;/a&gt;&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;Premature optimization is the root of all evil. - Donald Knuth&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For most applications, &lt;strong&gt;Master Tables should be the default choice&lt;/strong&gt; because they offer better performance, simpler queries, easier reporting, and lower maintenance costs.&lt;/p&gt;

&lt;p&gt;Use EAV only when flexibility is a core business requirement, such as custom fields or dynamic form builders.&lt;/p&gt;

&lt;p&gt;About the Author:Vatsal is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;. Building web magic with Laravel, PHP, MySQL, Vue.js &amp;amp; more.&lt;/p&gt;

</description>
      <category>databasedesign</category>
      <category>laravel</category>
      <category>architecture</category>
      <category>erp</category>
    </item>
    <item>
      <title>API Contract-Driven Development (Build Reliable Systems Without Guesswork)</title>
      <dc:creator>Ankit Parmar</dc:creator>
      <pubDate>Wed, 27 May 2026 10:23:48 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/api-contract-driven-development-build-reliable-systems-without-guesswork-lef</link>
      <guid>https://dev.to/addwebsolutionpvtltd/api-contract-driven-development-build-reliable-systems-without-guesswork-lef</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“A big part of the essence of building a program is in fact the debugging of the specification.” - Fred Brooks&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Modern applications often fail not because of bad code-but because of misaligned expectations between frontend and backend. APIs change, fields break, and teams waste time debugging integration issues.&lt;/p&gt;

&lt;p&gt;API Contract-Driven Development fixes this at the root.&lt;/p&gt;

&lt;p&gt;Instead of building first and integrating later, teams define the API contract upfront, align on it, and then implement against that contract independently.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore how Contract-Driven Development works, why it matters, and how it enables scalable, predictable systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why API Contracts Matter
&lt;/h2&gt;

&lt;p&gt;Without a defined contract, teams face:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Breaking API changes&lt;/li&gt;
&lt;li&gt;Miscommunication between frontend and backend&lt;/li&gt;
&lt;li&gt;Delayed integrations&lt;/li&gt;
&lt;li&gt;Fragile deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contracts solve this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defining clear expectations upfront&lt;/li&gt;
&lt;li&gt;Acting as a single source of truth&lt;/li&gt;
&lt;li&gt;Enabling parallel development&lt;/li&gt;
&lt;li&gt;Preventing unexpected breaking changes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Is Contract-Driven Development?
&lt;/h2&gt;

&lt;p&gt;Contract-Driven Development (CDD) is an approach where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API structure is defined before implementation&lt;/li&gt;
&lt;li&gt;Both frontend and backend agree on the contract&lt;/li&gt;
&lt;li&gt;Development happens independently but consistently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A contract includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Endpoints&lt;/li&gt;
&lt;li&gt;Request/response structure&lt;/li&gt;
&lt;li&gt;Data types&lt;/li&gt;
&lt;li&gt;Error formats&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Core Philosophy
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“The interface is the system.” - Alan Kay&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The contract defines how systems interact-everything else is implementation detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;API contracts eliminate ambiguity between teams&lt;/li&gt;
&lt;li&gt;Enable parallel frontend and backend development&lt;/li&gt;
&lt;li&gt;Reduce integration bugs and rework&lt;/li&gt;
&lt;li&gt;Improve system reliability and predictability&lt;/li&gt;
&lt;li&gt;Work best with tools like OpenAPI and schema validation&lt;/li&gt;
&lt;li&gt;Essential for scaling teams and microservices&lt;/li&gt;
&lt;li&gt;Promote clear ownership and accountability&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What Is an API Contract?&lt;/li&gt;
&lt;li&gt;Contract-First vs Code-First&lt;/li&gt;
&lt;li&gt;How Contract-Driven Development Works&lt;/li&gt;
&lt;li&gt;Architecture Overview&lt;/li&gt;
&lt;li&gt;Defining API Contracts (Conceptual)&lt;/li&gt;
&lt;li&gt;Development Workflow&lt;/li&gt;
&lt;li&gt;Validation and Testing&lt;/li&gt;
&lt;li&gt;Versioning and Evolution&lt;/li&gt;
&lt;li&gt;Tooling and Ecosystem&lt;/li&gt;
&lt;li&gt;Why This Approach Makes Sense&lt;/li&gt;
&lt;li&gt;Watch Out For&lt;/li&gt;
&lt;li&gt;Next Steps You Can Take&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;FAQ&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;As systems grow, frontend and backend teams often move independently. Without a shared agreement, APIs become a moving target-leading to broken integrations and wasted time.&lt;/p&gt;

&lt;p&gt;Contract-Driven Development introduces structure. By defining the API upfront, teams align early and build with confidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What Is an API Contract?
&lt;/h2&gt;

&lt;p&gt;An API contract is a formal agreement that defines how two systems communicate.&lt;br&gt;
It specifies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Endpoint paths&lt;/li&gt;
&lt;li&gt;HTTP methods&lt;/li&gt;
&lt;li&gt;Request payloads&lt;/li&gt;
&lt;li&gt;Response formats&lt;/li&gt;
&lt;li&gt;Status codes&lt;/li&gt;
&lt;li&gt;Error structures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as a blueprint for communication.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The most damaging phrase in the language is: ‘It’s always been done this way.’” - Grace Hopper&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Contract-First vs Code-First
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Contract-First (Recommended)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define API using schema (OpenAPI, JSON Schema)&lt;/li&gt;
&lt;li&gt;Generate mocks and clients&lt;/li&gt;
&lt;li&gt;Implement backend afterward&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code-First&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build backend first&lt;/li&gt;
&lt;li&gt;Document later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Documentation often becomes outdated&lt;/li&gt;
&lt;li&gt;Frontend depends on unstable APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. How Contract-Driven Development Works
&lt;/h2&gt;

&lt;p&gt;High-level flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define API contract&lt;/li&gt;
&lt;li&gt;Share with teams&lt;/li&gt;
&lt;li&gt;Generate mocks&lt;/li&gt;
&lt;li&gt;Frontend builds against mock API&lt;/li&gt;
&lt;li&gt;Backend implements contract&lt;/li&gt;
&lt;li&gt;Validate both sides&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No surprises during integration&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Architecture Overview
&lt;/h2&gt;

&lt;p&gt;Frontend (React / Mobile)&lt;br&gt;
 ↓&lt;br&gt;
 API Contract (OpenAPI)&lt;br&gt;
 ↓&lt;br&gt;
 Backend Implementation&lt;br&gt;
 ↓&lt;br&gt;
 Validation Layer&lt;br&gt;
Key idea:&lt;br&gt;
 The contract sits in the middle as the source of truth.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Controlling complexity is the essence of computer programming.” - Brian Kernighan&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6. Defining API Contracts (Conceptual)
&lt;/h2&gt;

&lt;p&gt;A contract is typically written using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAPI (Swagger)&lt;/li&gt;
&lt;li&gt;JSON Schema&lt;/li&gt;
&lt;li&gt;GraphQL schema&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example (simplified):&lt;/p&gt;

&lt;p&gt;paths:&lt;br&gt;
 /users:&lt;br&gt;
   get:&lt;br&gt;
     responses:&lt;br&gt;
       200:&lt;br&gt;
         description: List users&lt;br&gt;
         content:&lt;br&gt;
           application/json:&lt;br&gt;
             schema:&lt;br&gt;
               type: array&lt;br&gt;
               items:&lt;br&gt;
                 type: object&lt;br&gt;
                 properties:&lt;br&gt;
                   id:&lt;br&gt;
                     type: integer&lt;br&gt;
                   name:&lt;br&gt;
                     type: string&lt;/p&gt;

&lt;p&gt;This defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Structure&lt;/li&gt;
&lt;li&gt;Types&lt;/li&gt;
&lt;li&gt;Expected response&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Development Workflow
&lt;/h2&gt;

&lt;p&gt;Step 1: Define contract&lt;br&gt;
Step 2: Review with team&lt;br&gt;
Step 3: Generate mock server&lt;br&gt;
Step 4: Frontend development&lt;br&gt;
Step 5: Backend implementation&lt;br&gt;
Step 6: Contract validation&lt;/p&gt;

&lt;p&gt;Parallel development becomes possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Validation and Testing
&lt;/h2&gt;

&lt;p&gt;Contracts are enforced using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schema validation&lt;/li&gt;
&lt;li&gt;Contract testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two key approaches:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consumer-Driven Contracts&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend defines expectations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Provider Validation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend ensures it matches contract&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pact&lt;/li&gt;
&lt;li&gt;Postman&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Versioning and Evolution
&lt;/h2&gt;

&lt;p&gt;APIs evolve. Contracts help manage change safely.&lt;br&gt;
Best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use versioning (/v1, /v2)&lt;/li&gt;
&lt;li&gt;Avoid breaking changes&lt;/li&gt;
&lt;li&gt;Deprecate gradually&lt;/li&gt;
&lt;li&gt;Maintain backward compatibility&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“Simplicity is prerequisite for reliability.” - Edsger W. Dijkstra&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  10. Tooling and Ecosystem
&lt;/h2&gt;

&lt;p&gt;Popular tools include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAPI Specification&lt;/li&gt;
&lt;li&gt;Swagger&lt;/li&gt;
&lt;li&gt;Stoplight&lt;/li&gt;
&lt;li&gt;Insomnia&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tools help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Design APIs&lt;/li&gt;
&lt;li&gt;Generate docs&lt;/li&gt;
&lt;li&gt;Create mocks&lt;/li&gt;
&lt;li&gt;Validate contracts&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  11. Why This Approach Makes Sense
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Eliminates ambiguity&lt;/li&gt;
&lt;li&gt;Reduces integration issues&lt;/li&gt;
&lt;li&gt;Enables parallel development&lt;/li&gt;
&lt;li&gt;Improves developer productivity&lt;/li&gt;
&lt;li&gt;Scales across teams and services&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  12. Watch Out For
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Over-engineering simple APIs&lt;/li&gt;
&lt;li&gt;Poorly defined contracts&lt;/li&gt;
&lt;li&gt;Lack of versioning strategy&lt;/li&gt;
&lt;li&gt;Ignoring backward compatibility&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  13. Next Steps You Can Take
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduce OpenAPI in your project&lt;/li&gt;
&lt;li&gt;Add contract validation in CI/CD&lt;/li&gt;
&lt;li&gt;Generate mock APIs for frontend&lt;/li&gt;
&lt;li&gt;Adopt contract testing tools&lt;/li&gt;
&lt;li&gt;Document APIs properly&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  14. Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Contract-first development is widely used in microservices architectures. &lt;a href="https://microservices.io/patterns/apigateway.html" rel="noopener noreferrer"&gt;https://microservices.io/patterns/apigateway.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;API contracts act as a single source of truth across teams. &lt;a href="https://stoplight.io/api-design-guide" rel="noopener noreferrer"&gt;https://stoplight.io/api-design-guide&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contract testing significantly reduces integration failures in production.&lt;a href="https://martinfowler.com/articles/consumerDrivenContracts.html" rel="noopener noreferrer"&gt;https://martinfowler.com/articles/consumerDrivenContracts.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  15. FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Is contract-driven development only for large systems?&lt;/strong&gt;&lt;br&gt;
No, it’s useful even for small teams to avoid confusion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Is this the same as API documentation?&lt;/strong&gt;&lt;br&gt;
No. Documentation is derived from the contract, not the source.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Can I use this with GraphQL?&lt;/strong&gt;&lt;br&gt;
Yes. GraphQL schema acts as a contract.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Does this slow down development?&lt;/strong&gt;&lt;br&gt;
Initially slightly-but saves massive time later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Is it required for microservices?&lt;/strong&gt;&lt;br&gt;
Highly recommended.&lt;/p&gt;

&lt;h2&gt;
  
  
  16. Conclusion
&lt;/h2&gt;

&lt;p&gt;API Contract-Driven Development brings clarity to one of the most fragile parts of modern systems-communication between services.&lt;/p&gt;

&lt;p&gt;By defining expectations upfront, you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Predictable integrations&lt;/li&gt;
&lt;li&gt;Faster development&lt;/li&gt;
&lt;li&gt;Fewer bugs&lt;/li&gt;
&lt;li&gt;Better scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your team struggles with broken APIs, miscommunication, or slow integration cycles, adopting a contract-first approach is a practical, high-impact improvement.&lt;/p&gt;

&lt;p&gt;About the Author:&lt;em&gt;Ankit is a full-stack developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt; and AI enthusiast who crafts intelligent web solutions with PHP, Laravel, and modern frontend tools.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>backenddevelopment</category>
      <category>contractdrivendevelopment</category>
      <category>openai</category>
    </item>
    <item>
      <title>Designing Permission Systems Beyond RBAC (ABAC)</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Tue, 26 May 2026 08:04:47 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/designing-permission-systems-beyond-rbac-abac-1f44</link>
      <guid>https://dev.to/addwebsolutionpvtltd/designing-permission-systems-beyond-rbac-abac-1f44</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Simple permissions work for small systems. Context-aware permissions power enterprise systems.” &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;RBAC breaks down at scale&lt;/li&gt;
&lt;li&gt;ABAC enables dynamic, context-aware authorization&lt;/li&gt;
&lt;li&gt;Permissions should depend on attributes, not only roles&lt;/li&gt;
&lt;li&gt;Centralized policy engines improve maintainability&lt;/li&gt;
&lt;li&gt;Fine-grained authorization is essential for modern SaaS&lt;/li&gt;
&lt;li&gt;Performance and caching are critical in permission systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Most applications start with simple role-based permissions: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Admin - Full access&lt;/li&gt;
&lt;li&gt;Editor - Edit content&lt;/li&gt;
&lt;li&gt;Viewer - Read-only access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This works initially.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;But as systems grow, requirements become more complex:&lt;/li&gt;
&lt;li&gt;Managers can edit only their department’s data&lt;/li&gt;
&lt;li&gt;Support agents can access tickets only during work hours&lt;/li&gt;
&lt;li&gt;Users can download reports only from trusted devices&lt;/li&gt;
&lt;li&gt;Contractors lose access after project expiration
Traditional RBAC (Role-Based Access Control) struggles to handle these dynamic conditions cleanly. This is where ABAC (Attribute-Based Access Control) becomes essential.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What role does this user have?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;ABAC asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Should this specific user perform this action on this resource under these conditions?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That difference changes everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Why Traditional RBAC Fails at Scale&lt;/li&gt;
&lt;li&gt;Core Concepts of ABAC&lt;/li&gt;
&lt;li&gt;RBAC vs ABAC (Deep Comparison)&lt;/li&gt;
&lt;li&gt;Core Principles of Modern Permission Architecture&lt;/li&gt;
&lt;li&gt;Designing a Scalable Authorization System&lt;/li&gt;
&lt;li&gt;Policy Engine Architecture&lt;/li&gt;
&lt;li&gt;Attribute Modeling Strategy&lt;/li&gt;
&lt;li&gt;Multi-Tenant Permission Design&lt;/li&gt;
&lt;li&gt;Real-Time Authorization Challenges&lt;/li&gt;
&lt;li&gt;Caching &amp;amp; Performance Optimization&lt;/li&gt;
&lt;li&gt;Frontend Authorization Patterns&lt;/li&gt;
&lt;li&gt;Backend Enforcement Strategy&lt;/li&gt;
&lt;li&gt;Audit Logging &amp;amp; Compliance&lt;/li&gt;
&lt;li&gt;Testing Authorization Systems&lt;/li&gt;
&lt;li&gt;Real-World Example (Enterprise SaaS)&lt;/li&gt;
&lt;li&gt;Interesting Facts&lt;/li&gt;
&lt;li&gt;Stats&lt;/li&gt;
&lt;li&gt;FAQ’s&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Traditional RBAC Fails at Scale
&lt;/h2&gt;

&lt;p&gt;RBAC becomes difficult in enterprise systems because permissions explode over time.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Admin
RegionalAdmin
RegionalManager
RegionalManagerReadOnly
FinanceManager
FinanceManagerEU
FinanceManagerUS
SupportLevel1
SupportLevel2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soon you face: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Role explosion &amp;amp; Duplicate permissions&lt;/li&gt;
&lt;li&gt;Hardcoded business logic&lt;/li&gt;
&lt;li&gt;Complex exception handling&lt;/li&gt;
&lt;li&gt;Difficult audits&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“Every special-case role is usually a hidden architecture problem.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Core Concepts of ABAC
&lt;/h2&gt;

&lt;p&gt;ABAC evaluates permissions using attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. User Attributes&lt;/strong&gt;&lt;br&gt;
Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;department = finance
region = EU
employmentType = contractor
clearanceLevel = 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Resource Attributes&lt;/strong&gt;&lt;br&gt;
Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.ownerId
document.region
document.classification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Action Attributes&lt;/strong&gt;&lt;br&gt;
Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read
write
delete
approve
export
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Environment Attributes&lt;/strong&gt;&lt;br&gt;
Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;currentTime
IP address
device type
geo location
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  RBAC vs ABAC (Deep Comparison)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnpszrhrqwmw0raiad7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnpszrhrqwmw0raiad7b.png" alt=" " width="632" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Principles of Modern Permission Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Centralized Authorization&lt;/strong&gt;&lt;br&gt;
Never scatter permission checks everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad&lt;/strong&gt;&lt;br&gt;
if (user.role === 'admin') {}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Better&lt;/strong&gt;&lt;br&gt;
authorizationService.can(user, 'delete', project)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Policy-Based Design&lt;/strong&gt;&lt;br&gt;
Permissions should be defined as policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
Managers can edit invoices in their own department.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOT:&lt;/strong&gt;&lt;br&gt;
if role === manager &amp;amp;&amp;amp; department === ...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Least Privilege Principle&lt;/strong&gt;&lt;br&gt;
Users should receive the minimum access necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This minimizes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Security risks&lt;/li&gt;
&lt;li&gt;Data leaks&lt;/li&gt;
&lt;li&gt;Insider threats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Deny by Default&lt;/strong&gt;&lt;br&gt;
If no rule explicitly allows access:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ACCESS = DENIED&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always.&lt;/p&gt;
&lt;h2&gt;
  
  
  Designing a Scalable Authorization System
&lt;/h2&gt;

&lt;p&gt;Recommended High-Level Architecture&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Client
   ↓
  API Gateway
   ↓
   Authorization Layer
   ↓
   Policy Engine
   ↓
   Attribute Store
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Folder Structure Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
│
├── auth/
│   ├── policies/
│   ├── guards/
│   ├── attributes/
│   ├── services/
│   ├── engines/
│   └── audit/
│
├── features/
│   ├── billing/
│   ├── analytics/
│   └── users/
│
├── shared/
└── core/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;“Authorization logic is infrastructure, not UI logic.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Policy Engine Architecture
&lt;/h2&gt;

&lt;p&gt;A policy engine evaluates authorization decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Flow&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User requests action
↓
Load user attributes
↓
Load resource attributes
↓
Evaluate policies
↓
Return allow/deny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Policy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const invoicePolicy = {
 action: 'edit',
 resource: 'invoice',
 evaluate: ({ user, resource }) =&amp;gt; {
   return (
     user.department === resource.department &amp;amp;&amp;amp;
     user.clearanceLevel &amp;gt;= 2
   );
 }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Attribute Modeling Strategy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Poor attribute design creates long-term problems.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Good Attribute Categories&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu8k40wwfopwbobu1o0sq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu8k40wwfopwbobu1o0sq.png" alt=" " width="633" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid&lt;/strong&gt;&lt;br&gt;
Storing derived permissions directly&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad:&lt;/strong&gt;&lt;br&gt;
canEditInvoices = true&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Better:&lt;/strong&gt;&lt;br&gt;
department = finance&lt;br&gt;
role = manager&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Tenant Permission Design&lt;/strong&gt;&lt;br&gt;
Enterprise SaaS applications require tenant isolation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
Tenant A users must NEVER access Tenant B data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every authorization check should include:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;resource.tenantId === user.tenantId&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Missing this is one of the most dangerous SaaS security bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-Time Authorization Challenges&lt;/strong&gt;&lt;br&gt;
Permissions can change instantly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User suspension&lt;/li&gt;
&lt;li&gt;Role updates&lt;/li&gt;
&lt;li&gt;Subscription expiration&lt;/li&gt;
&lt;li&gt;Emergency revocation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stale JWT permissions&lt;/li&gt;
&lt;li&gt;Cached authorization data&lt;/li&gt;
&lt;li&gt;Distributed systems consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Recommended:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Short-lived tokens&lt;/li&gt;
&lt;li&gt;Server-side validation&lt;/li&gt;
&lt;li&gt;Permission versioning&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Caching &amp;amp; Performance Optimization
&lt;/h2&gt;

&lt;p&gt;Authorization can become expensive at scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Large systems may process:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Millions of permission checks per minute&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimization Strategies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Policy Caching&lt;/strong&gt;&lt;br&gt;
Cache compiled policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Attribute Caching&lt;/strong&gt;&lt;br&gt;
Use Redis for frequently accessed attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Decision Memoization&lt;/strong&gt;&lt;br&gt;
Cache repeated authorization decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Batch Authorization&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Instead of:&lt;/strong&gt;&lt;br&gt;
1000 separate permission checks&lt;br&gt;
&lt;strong&gt;Use:&lt;/strong&gt;&lt;br&gt;
1 bulk evaluation&lt;/p&gt;
&lt;h2&gt;
  
  
  Frontend Authorization Patterns
&lt;/h2&gt;

&lt;p&gt;Frontend authorization is for UX only.&lt;br&gt;
Backend authorization is mandatory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Frontend Pattern&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Can action="edit" resource="invoice"&amp;gt;
 &amp;lt;EditButton /&amp;gt;
&amp;lt;/Can&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Avoid&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Relying solely on hidden buttons&lt;br&gt;
Attackers can still call APIs directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backend Enforcement Strategy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Backend APIs must ALWAYS enforce authorization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/invoice/:id', async (req, res) =&amp;gt; {
 const allowed = await auth.can(
   req.user,
   'edit',
   invoice
 );

 if (!allowed) {
   return res.status(403).json({
     error: 'Forbidden'
   });
 }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;“UI permissions improve experience. Backend permissions protect systems.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Audit Logging &amp;amp; Compliance
&lt;/h2&gt;

&lt;p&gt;Modern enterprises require full auditability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Track:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who accessed what&lt;/li&gt;
&lt;li&gt;When access occurred&lt;/li&gt;
&lt;li&gt;Why permission was granted&lt;/li&gt;
&lt;li&gt;Policy evaluation result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User 482 edited invoice 882&lt;/li&gt;
&lt;li&gt;Policy: FinanceManagerPolicy&lt;/li&gt;
&lt;li&gt;Timestamp: 2026-05-22T10:14Z&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Critical for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SOC2&lt;/li&gt;
&lt;li&gt;HIPAA&lt;/li&gt;
&lt;li&gt;GDPR&lt;/li&gt;
&lt;li&gt;ISO compliance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing Authorization Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Authorization bugs are security bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommended Testing Levels&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwjcfq9m1he8i7tgsbi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwjcfq9m1he8i7tgsbi9.png" alt=" " width="635" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('contractor cannot access finance data', () =&amp;gt; {
 const result = canAccess(contractor, financeReport);
 expect(result).toBe(false);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real-World Example (Enterprise SaaS)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A project management platform requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Admins - Full access&lt;/li&gt;
&lt;li&gt;Managers - Manage own teams&lt;/li&gt;
&lt;li&gt;Contractors - Limited projects only&lt;/li&gt;
&lt;li&gt;Clients - Read-only assigned projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Authorization Service&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const canAccessProject = ({ user,  project,  action }) =&amp;gt; {
 if (user.role === 'admin') {
   return true;
 }
 if (user.teamId === project.teamId &amp;amp;&amp;amp; action !== 'delete' ) {
   return true;
 }
 return false;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Frontend Usage&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Can action="update" resource={project}&amp;gt;
   &amp;lt;ProjectSettings /&amp;gt;
&amp;lt;/Can&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API Enforcement&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!canAccessProject({ user, project, action })) {
  throw new ForbiddenError();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ABAC originated from military-grade access control systems where contextual authorization was mandatory. &lt;a href="https://www.nist.gov/publications/guide-attribute-based-access-control-abac-definition-and-considerations?" rel="noopener noreferrer"&gt;NIST ABAC Guide&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Google’s BeyondCorp security model heavily relies on context-aware authorization principles. &lt;a href="https://cloud.google.com/beyondcorp?" rel="noopener noreferrer"&gt;Google BeyondCorp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Modern cloud IAM systems from AWS and Azure support ABAC-style policies.&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html?" rel="noopener noreferrer"&gt;AWS IAM ABAC Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Policy engines like OPA (Open Policy Agent) are increasingly adopted in Kubernetes and cloud-native systems.&lt;a href="https://www.openpolicyagent.org/?" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fine-grained authorization is becoming a core requirement for enterprise SaaS platforms due to increasing compliance and multi-tenant security demands. Auth Authorization Trends](&lt;a href="https://auth0.com/blog/what-is-abac-and-how-to-implement-it/" rel="noopener noreferrer"&gt;https://auth0.com/blog/what-is-abac-and-how-to-implement-it/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Open Policy Agent is widely adopted across cloud-native infrastructure for centralized policy enforcement.&lt;a href="https://www.cncf.io/projects/open-policy-agent-opa/" rel="noopener noreferrer"&gt;CNCF OPA Project&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Zero Trust architectures increasingly depend on contextual authorization instead of static role systems. &lt;a href="https://learn.microsoft.com/en-us/security/zero-trust/zero-trust-overview?" rel="noopener noreferrer"&gt;Microsoft Zero Trust Model&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ’s
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q1. Is RBAC obsolete?&lt;/strong&gt;&lt;br&gt;
No. RBAC is still useful.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RBAC for broad roles&lt;/li&gt;
&lt;li&gt;ABAC for fine-grained rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Q2. Is ABAC harder to implement?&lt;/strong&gt;&lt;br&gt;
Yes, but it scales much better for complex systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3. Should authorization live in the frontend?&lt;/strong&gt;&lt;br&gt;
No.Frontend checks are UX enhancements only and Backend enforcement is mandatory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q4. What is the biggest authorization mistake?&lt;/strong&gt;&lt;br&gt;
Embedding permission logic directly inside business code everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q5. Which companies benefit most from ABAC?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enterprise SaaS&lt;/li&gt;
&lt;li&gt;FinTech&lt;/li&gt;
&lt;li&gt;Healthcare&lt;/li&gt;
&lt;li&gt;Government systems&lt;/li&gt;
&lt;li&gt;Multi-tenant platforms&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Modern applications require more than static roles.&lt;/p&gt;

&lt;p&gt;As systems scale, authorization becomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context-aware&lt;/li&gt;
&lt;li&gt;Dynamic&lt;/li&gt;
&lt;li&gt;Fine-grained&lt;/li&gt;
&lt;li&gt;Policy-driven
The future of scalable security architecture lies beyond simple RBAC systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By adopting ABAC principles, centralized policy engines, and clean authorization architecture, teams can build systems that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More secure&lt;/li&gt;
&lt;li&gt;Easier to scale&lt;/li&gt;
&lt;li&gt;Easier to audit&lt;/li&gt;
&lt;li&gt;Easier to maintain&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“Authentication identifies users. Authorization defines boundaries.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;About the Author:&lt;em&gt;Mayank is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;, building scalable apps with PHP, Node.js &amp;amp; React. Sharing ideas, code, and creativity.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>backenddevelopment</category>
      <category>systemdesign</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Handling Long-Running Processes in UI</title>
      <dc:creator>Abodh Kumar</dc:creator>
      <pubDate>Fri, 22 May 2026 10:47:24 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/handling-long-running-processes-in-ui-18hm</link>
      <guid>https://dev.to/addwebsolutionpvtltd/handling-long-running-processes-in-ui-18hm</guid>
      <description>&lt;p&gt;In modern web and desktop applications, users routinely trigger operations that cannot complete in a single render cycle - file uploads, video transcoding, AI generation, data exports, batch imports, report generation, and complex calculations. Unlike a simple API call that resolves in milliseconds, these processes can take seconds, minutes, or even hours. How your interface communicates progress, allows cancellation, and survives navigation defines whether users trust your application or abandon it mid-task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaway
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Always model four states - queued, running, completed, and failed - for every long-running process, no exceptions.&lt;/li&gt;
&lt;li&gt;Show determinate progress (with a percentage or ETA) whenever the duration is predictable; never leave users guessing how long they have to wait.&lt;/li&gt;
&lt;li&gt;Decouple long-running work from the component lifecycle - the user must be free to navigate without aborting the task.&lt;/li&gt;
&lt;li&gt;Provide cancellation for any process that takes longer than three seconds; users must always feel in control.&lt;/li&gt;
&lt;li&gt;Use Web Workers, background tabs, or server-side jobs to keep the main thread responsive during heavy computation.&lt;/li&gt;
&lt;li&gt;Persist process state across reloads and navigations so users can recover after refresh, network drops, or accidental tab closures.&lt;/li&gt;
&lt;li&gt;Notify users on completion through in-app toasts, browser notifications, or email - never expect them to keep watching the screen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Understanding the Four Process States&lt;/li&gt;
&lt;li&gt;Communicating Progress - Determinate, Indeterminate &amp;amp; Multi-Stage&lt;/li&gt;
&lt;li&gt;Handling Cancellation, Failure &amp;amp; Recovery&lt;/li&gt;
&lt;li&gt;Building a Custom useLongRunningTask Hook&lt;/li&gt;
&lt;li&gt;Advanced Techniques&lt;/li&gt;
&lt;li&gt;Stats &amp;amp; Interesting Facts&lt;/li&gt;
&lt;li&gt;FAQ&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;A long-running process is any operation whose duration exceeds the user's natural attention span for a single interaction - generally anything beyond two to three seconds. Examples are everywhere in modern software: uploading a 500 MB video, running an AI image generation job, exporting a 100,000-row spreadsheet, transcoding audio, performing a database migration triggered from an admin panel, or compiling a project in a browser-based IDE.&lt;/p&gt;

&lt;p&gt;These processes share a common trait: the user initiates them, then has nothing to do but wait. If your interface handles that wait poorly - by freezing, hiding, or silently failing - users assume your application is broken. Worse, they may close the tab, lose their work, and never return.&lt;/p&gt;

&lt;p&gt;Done well, long-running process UX feels almost magical. The user uploads a file, sees a clear progress indicator, navigates to another page, gets a notification when the upload finishes, and never once feels trapped. Done badly, the same operation produces a frozen browser tab, an indefinite spinner, and a frustrated user.&lt;/p&gt;

&lt;p&gt;This article covers a complete strategy for handling long-running processes in modern web UIs - from foundational state modeling and progress indicators to background workers, cancellation patterns, resumable uploads, and cross-session persistence.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Understanding the Four Process States
&lt;/h2&gt;

&lt;p&gt;Unlike short API calls (which only need three states), long-running processes require a richer state model. Every long-running task should be in exactly one of these four states at any given moment:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.1 The Queued State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The queued state exists from the moment the user triggers the action until the process actually begins executing. This is non-trivial: many systems queue work behind a rate limiter, a worker pool, or a server-side job queue. The user needs to know their request was accepted, where they are in the queue, and roughly when execution will start. Skipping this state and jumping straight to "running" lies to the user when there is real waiting time before any work happens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.2 The Running State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The running state covers the actual execution. This is where progress communication matters most. Depending on the nature of the task, you may know the percentage complete (a file upload), the current step out of N (a multi-stage pipeline), or only that work is happening (an open-ended AI generation). Each calls for a different visual treatment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.3 The Completed State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the process finishes successfully, the UI must transition into a clear success state - ideally with a summary of what was produced, a link to the result, and an action the user can take next. A common mistake is to silently return to the previous screen, which leaves users uncertain whether the task actually succeeded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.4 The Failed or Cancelled State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Any failure - whether from a server error, a timeout, a quota exceedance, or an explicit user cancellation - must surface to the user with a clear explanation and, where applicable, a way to retry or resume. Cancellation deserves special treatment: it was intentional, so the message should confirm rather than alarm.&lt;/p&gt;

&lt;p&gt;A foundational pattern using a single status enum keeps these states explicit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useReducer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// idle | queued | running | completed | failed | cancelled&lt;/span&gt;
  &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queued&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fail&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ExportButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;startExport&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;job&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createExportJob&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unsubscribe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;subscribeToJob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;onProgress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
      &lt;span class="na"&gt;onComplete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
      &lt;span class="na"&gt;onError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fail&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;startExport&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Start&lt;/span&gt; &lt;span class="nx"&gt;Export&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queued&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;QueuedIndicator&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProgressBar&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DownloadLink&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ErrorPanel&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onRetry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;startExport&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CancelledNotice&lt;/span&gt; &lt;span class="nx"&gt;onRestart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;startExport&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Communicating Progress - Determinate, Indeterminate &amp;amp; Multi-Stage
&lt;/h2&gt;

&lt;p&gt;The single biggest factor in how users tolerate waiting is whether they can predict how much longer they have to wait. Research in UX psychology consistently shows that perceived duration is far more important than actual duration - and the right progress indicator can make a 30-second wait feel shorter than a 10-second wait with no feedback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.1 Determinate Progress Bars - When You Know the Total&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A determinate progress bar shows a percentage, an ETA, or both. Use it whenever you can reasonably estimate the total work - file uploads (you know the byte size), batch imports (you know the row count), or paginated data exports (you know the page count). Always pair the visual bar with a numeric percentage and, if possible, an estimated time remaining.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ProgressBar&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;etaSeconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progress-container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progressbar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
         &lt;span class="nx"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;valuenow&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;valuemin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;valuemax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
         &lt;span class="nx"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progress-track&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progress-fill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;%`&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progress-meta&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;%&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;etaSeconds&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;formatEta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;etaSeconds&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="nx"&gt;remaining&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;formatEta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;s`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;m`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;h`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.2 Indeterminate Indicators - For Unknown Durations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some tasks have genuinely unknowable duration: an AI text generation, a complex SQL query, or any process behind an opaque external service. In these cases, a determinate bar would be a lie. Use an indeterminate animation - a sweeping bar, a pulsing shape, or a series of step descriptions - to communicate "we are working" without falsely promising a specific finish time. Where possible, replace pure motion with descriptive status text that updates as the task progresses ("Analyzing input...", "Generating response...", "Finalizing output...").&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;IndeterminateProgress&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;stage&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;indeterminate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;status&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;indeterminate-bar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stage-label&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Working...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// CSS&lt;/span&gt;
&lt;span class="cm"&gt;/*
.indeterminate-bar {
  position: relative;
  height: 4px;
  background: #e0e0e0;
  overflow: hidden;
  border-radius: 2px;
}
.indeterminate-bar::after {
  content: '';
  position: absolute;
  height: 100%;
  width: 30%;
  background: #4a90e2;
  animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide {
  0%   { left: -30%; }
  100% { left: 100%; }
}
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.3 Multi-Stage Progress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Many real-world processes are pipelines: upload → validate → process → export → notify. A single progress bar collapses this into one number, hiding useful information. A stepper or checklist UI exposes each stage individually, so the user sees not only "we are 60% done" but "we just finished processing and are now exporting." This builds confidence that the system is making real progress, especially for long pipelines where any single stage may pause for a while.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MultiStageProgress&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentStage&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ol&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stage-list&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;currentStage&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;currentStage&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pending&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`stage stage-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stage-icon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;✓&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Spinner&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pending&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;○&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stage-label&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;detail&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stage-detail&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="p"&gt;)}&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ol&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The function of design is letting design function. - Micha Commeren&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. Handling Cancellation, Failure &amp;amp; Recovery
&lt;/h2&gt;

&lt;p&gt;A process that cannot be cancelled is a trap. A process that fails without explanation is worse. Robust long-running UX treats cancellation, failure, and recovery as first-class concerns rather than afterthoughts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.1 Cancellation - Always Available, Always Clean&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Any process taking longer than three seconds should expose a cancel control. Cancellation must be honest: if the work is already partially complete on the server, the UI must explain what happens to that partial result (kept, discarded, or rolled back). Silent or unreliable cancellation - where the button does nothing or the work continues anyway - destroys user trust faster than an outright crash.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;CancellableUpload&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controllerRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;uploadFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;onProgress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AbortError&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProgressBar&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Cancel&lt;/span&gt; &lt;span class="nx"&gt;upload&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Upload&lt;/span&gt; &lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="nx"&gt;was&lt;/span&gt; &lt;span class="nx"&gt;saved&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.2 Distinguishing Failure Modes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Long-running failures are not all the same. Group them into categories your UI can respond to differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recoverable network failures - The connection dropped mid-upload. Offer automatic retry, ideally resuming from the last successful chunk rather than restarting.&lt;/li&gt;
&lt;li&gt;Server-side processing errors - The server accepted the input but couldn't complete the work (transcoding error, malformed data row, AI safety rejection). Show the specific reason and, where possible, a way to fix and retry.&lt;/li&gt;
&lt;li&gt;Quota or limit errors - The user hit a plan limit, rate limit, or storage cap. Surface the specific limit and a clear path to resolve it (upgrade, free up space, wait).&lt;/li&gt;
&lt;li&gt;Timeouts - The process exceeded a maximum allowed duration. Communicate this honestly rather than letting the spinner run indefinitely.&lt;/li&gt;
&lt;li&gt;User cancellation - Treat differently from failure. Confirm the cancellation succeeded, state what was kept or discarded, and offer a clear restart path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4.3 Recovery and Resumability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For any process that takes more than a few seconds, design for the assumption that something will go wrong - the network will drop, the tab will close, the laptop will sleep. The most resilient UIs persist process state to durable storage (IndexedDB, localStorage, or a server-side job record) so that on next load, the user can resume from where they left off.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useResumableUpload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;saved&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`upload:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;saved&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;saved&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`upload:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;CHUNK_SIZE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;CHUNK_SIZE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;uploadChunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;CHUNK_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`upload:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;resume&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Building a Custom useLongRunningTask Hook
&lt;/h2&gt;

&lt;p&gt;Repeating queue/run/cancel/recover logic in every component is unmaintainable. A custom hook centralizes the lifecycle, exposes a clean API to components, and ensures every long-running task in your app behaves consistently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.1 The useLongRunningTask Hook&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useLongRunningTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taskFn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controllerRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;taskFn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;onProgress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aborted&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AbortError&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fail&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskFn&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;controllerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reset&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;VideoExport&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;projectId&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLongRunningTask&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exportVideo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Export&lt;/span&gt; &lt;span class="nx"&gt;Video&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queued&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProgressBar&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Cancel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DownloadLink&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onDismiss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ErrorPanel&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onRetry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Export&lt;/span&gt; &lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Start&lt;/span&gt; &lt;span class="nx"&gt;over&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.2 Decoupling From the Component Lifecycle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A subtle but critical point: the hook above ties the task lifetime to the component that started it. If the user navigates away, the task is cancelled. For most long-running processes, that is the wrong default - users expect to start a job, leave the page, and find it still running when they return. The fix is to store the running task in a global state container (Zustand, Redux, or a React context provider above the router) so it survives navigation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zustand&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useTaskStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="c1"&gt;// taskId -&amp;gt; task state&lt;/span&gt;

  &lt;span class="nf"&gt;startTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taskFn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

    &lt;span class="nf"&gt;taskFn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;onProgress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;})),&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;})))&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;})));&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="nf"&gt;cancelTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;taskId&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now any component anywhere in the tree can read the task's current state, and the task continues to run regardless of which page is mounted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Progress is impossible without change, and those who cannot communicate progress will be assumed to have made none. - Adapted from George Bernard Shaw&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6. Advanced Techniques
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;6.1 Web Workers for CPU-Bound Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your long-running process is heavy computation in the browser - image processing, parsing a large CSV, encrypting a file - running it on the main thread will freeze the UI. A Web Worker moves the work to a background thread, keeping animations smooth and inputs responsive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useWorkerTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;workerUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;workerRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;workerUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;workerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;setProgress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;terminate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;workerRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;terminate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cancel&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.2 Server-Sent Events for Real-Time Progress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For long-running server-side jobs, polling for status is wasteful and laggy. Server-Sent Events (SSE) give you a one-way streaming connection that pushes progress updates as the server produces them - ideal for AI generation, video transcoding, or any workflow where the server is the source of truth.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useJobStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connecting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/jobs/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/stream`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Connection lost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.3 Browser Notifications and Tab-Title Updates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Users will not stare at a progress bar for ten minutes. They will switch tabs, check email, or walk away. To bring them back when the work is done, use the Notifications API for a native push and update the document title with a status icon so a glance at the tab strip tells them whether to come back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useCompletionNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;✓ Done — &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;originalTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;permission&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;granted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Process complete&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;✗ Failed — &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;originalTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;⏳ Working — &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;originalTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;originalTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always request notification permission contextually - at the moment the user starts a long task, not on page load. Cold-start permission prompts are denied 90% of the time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.4 Persistent Background Jobs With Service Workers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For uploads, exports, or syncs that should survive even if the user closes the tab, register a Service Worker with the Background Sync API. The browser holds the work in a queue and resumes it when the network is available, even if the originating page is gone. This pattern powers the "your message will be sent when you're back online" experience in modern messaging apps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;queueBackgroundUpload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serviceWorker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;reg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;upload-pending&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;stashFileInIndexedDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// In the service worker&lt;/span&gt;
&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sync&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;upload-pending&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;processQueuedUploads&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Stats &amp;amp; Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;According to research compiled by the Nielsen Norman Group, the upper limit for keeping a user's attention focused on a dialog without progress feedback is approximately 10 seconds - past this, users start switching context and may abandon the task entirely.
Source: &lt;a href="https://www.nngroup.com/articles/response-times-3-important-limits/" rel="noopener noreferrer"&gt;https://www.nngroup.com/articles/response-times-3-important-limits/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A study by Chris Harrison and colleagues at Carnegie Mellon University found that progress bars with backward-decelerating animation (fast at first, slowing down) are perceived as up to 12% faster than uniform progress bars covering the same actual time.
Source: &lt;a href="https://www.chrisharrison.net/index.php/Research/ProgressBars" rel="noopener noreferrer"&gt;https://www.chrisharrison.net/index.php/Research/ProgressBars&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Akamai's 2017 online retail performance report found that a two-second delay during a checkout-related process more than doubled the bounce rate. Long-running processes without clear progress feedback amplify this effect dramatically.Source:
&lt;a href="https://www.akamai.com/newsroom/press-release/akamai-releases-spring-2017-state-of-online-retail-performance-report" rel="noopener noreferrer"&gt;https://www.akamai.com/newsroom/press-release/akamai-releases-spring-2017-state-of-online-retail-performance-report&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;According to Cloudflare's State of Application Security report, large-file uploads abandoned mid-transfer due to lack of resumability cost e-commerce and SaaS platforms millions of dollars in lost user productivity each year.Source: &lt;a href="https://www.cloudflare.com/lp/state-of-application-security-report/" rel="noopener noreferrer"&gt;https://www.cloudflare.com/lp/state-of-application-security-report/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Chrome's Web Vitals data shows that pages with a Total Blocking Time over 600ms - common when long-running processes run on the main thread - have measurably higher abandonment rates than pages that offload work to Web Workers.Source: &lt;a href="https://web.dev/articles/tbt" rel="noopener noreferrer"&gt;https://web.dev/articles/tbt&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A 2024 study published by the Baymard Institute found that 27% of e-commerce checkout abandonment is attributable to interfaces that appear unresponsive during payment processing - a textbook long-running process UX failure.Source: &lt;a href="https://baymard.com/lists/cart-abandonment-rate" rel="noopener noreferrer"&gt;https://baymard.com/lists/cart-abandonment-rate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Stripe's developer documentation reports that approximately 8% of payment-confirmation flows experience a network interruption between request and confirmation, making resumable, idempotent process handling essential for financial UX.Source: &lt;a href="https://stripe.com/docs/payments/payment-intents" rel="noopener noreferrer"&gt;https://stripe.com/docs/payments/payment-intents&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. When should a process be treated as "long-running" and given a dedicated UX, rather than just a spinner?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: A useful heuristic is the three-second rule: any process that may take longer than three seconds in the 95th-percentile case deserves dedicated long-running UX. Below that threshold, a simple loading state is sufficient. Above it, you need progress feedback, cancellation, and survivability across navigation. Be honest about your real-world latency distribution, not the best case on a fast network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Should a long-running task be tied to a single component, or should it survive navigation?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: It depends on the user's mental model. If the task is conceptually local to the page (e.g., a search refinement), tying it to the component is fine. If the user thinks of the task as something they "started" - an upload, an export, a video render - it should survive navigation, ideally by living in a global state container or being driven by a server-side job that the UI subscribes to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. How do I show progress when the duration is genuinely unknown?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: Show an indeterminate animation paired with descriptive status text that updates as the process advances ("Connecting...", "Analyzing...", "Generating output..."). This gives the user something to read and watch, signals real progress, and avoids the lie of a fake percentage. Never display a fabricated ETA - users notice when bars stall at 99% and lose trust.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. What is the best way to cancel a long-running task that is partially complete on the server?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: Always be explicit about what cancellation means in the UI. If the server can roll back the partial work, say so ("Cancel and discard"). If the partial work will be kept, say that instead ("Cancel — your progress so far will be saved"). Ambiguity here causes users to hesitate or, worse, to refresh the page mid-task and lose data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. How should I handle a tab being closed in the middle of a long-running process?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: For client-driven processes, persist progress to IndexedDB or localStorage and offer to resume on next visit. For server-driven jobs, use a server-side job record so the work continues regardless of the client - the user can simply reconnect and the UI subscribes to the existing job. For uploads specifically, use a chunked, resumable protocol (tus.io is the open standard).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Should I use polling or streaming (SSE/WebSockets) for progress updates?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: Streaming is strictly better for user experience: lower latency, less server load, no wasted requests. Use polling only when streaming infrastructure is unavailable, or as a fallback when the stream connection drops. If you do poll, use exponential backoff and a maximum interval to avoid hammering the server for jobs that take hours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. How do I keep the UI responsive during a CPU-heavy process in the browser?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: Move the work to a Web Worker. The main thread is responsible for rendering and input handling - any long-running computation there will freeze the UI, drop frames, and make the page feel broken. Workers communicate via postMessage and have access to most APIs you need for compute-heavy tasks. For very large datasets, consider streaming results back in chunks rather than waiting for the entire computation to finish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. What's the right way to notify a user that a long-running task has finished if they've switched tabs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ans: Layer your notifications. First, update the document title with a status icon - users glance at tab strips constantly. Second, fire a Web Notification if permission has been granted. Third, for tasks that may complete after the user has fully closed the app, send an email or push notification from the backend. Never rely on a single channel; users check different channels at different times.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The most precious resource we all have is time. - Steve Jobs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  9. Conclusion
&lt;/h2&gt;

&lt;p&gt;Long-running processes are not edge cases - they are central to modern application UX. Every minute spent improving how your app handles uploads, exports, generations, and batch jobs returns disproportionate user trust. The strategies described in this article each address a specific dimension of that experience:&lt;/p&gt;

&lt;p&gt;Explicit four-state modeling ensures queued, running, completed, and failed are always represented, never collapsed or implicit.&lt;br&gt;
Progress communication - whether determinate, indeterminate, or multi-stage - turns waiting from a passive frustration into an informed wait.&lt;/p&gt;

&lt;p&gt;Cancellation and recovery put the user in control, ensuring no process can trap them or destroy work silently.&lt;br&gt;
Custom hooks and global stores decouple long-running tasks from the component lifecycle, so navigation and unmounts don't kill in-flight work.&lt;/p&gt;

&lt;p&gt;Web Workers, SSE, and Service Workers keep the UI responsive, pipe real-time updates, and let work survive tab closures.&lt;br&gt;
Notifications and title updates bring users back the moment their work is ready, instead of forcing them to babysit a progress bar.&lt;/p&gt;

&lt;p&gt;The browser and modern frameworks give you every primitive you need. The responsibility lies with developers to compose them with care, treat long-running UX as a design problem rather than an engineering afterthought, and remember that for many users the difference between a finished task and an abandoned one is whether the interface respected their time.&lt;/p&gt;

&lt;p&gt;The best long-running UX feels like a quiet promise kept. The user starts something, the system honors that intent through whatever conditions arise, and at the end - whether seconds or hours later - delivers the result clearly. That invisibility, that reliability, is the mark of mature product engineering.&lt;/p&gt;

&lt;p&gt;About the Author: &lt;em&gt;Abodh is a PHP and Laravel Developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWeb Solution&lt;/a&gt;, skilled in MySQL, REST APIs, JavaScript, Git, and Docker for building robust web applications.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>progressbar</category>
    </item>
    <item>
      <title>Accessibility (a11y) in Modern Apps</title>
      <dc:creator>Vatsal Acharya</dc:creator>
      <pubDate>Fri, 15 May 2026 12:17:50 +0000</pubDate>
      <link>https://dev.to/addwebsolutionpvtltd/accessibility-a11y-in-modern-apps-2oj0</link>
      <guid>https://dev.to/addwebsolutionpvtltd/accessibility-a11y-in-modern-apps-2oj0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” - Tim Berners-Lee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Accessibility (a11y) ensures apps are usable by everyone, including people with disabilities&lt;/li&gt;
&lt;li&gt;It improves UX, SEO, and performance, not just compliance&lt;/li&gt;
&lt;li&gt;Modern apps must support keyboard navigation, screen readers, and visual adjustments&lt;/li&gt;
&lt;li&gt;Ignoring accessibility leads to real business loss + legal risks&lt;/li&gt;
&lt;li&gt;Accessibility is not a feature - it’s a foundation&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is Accessibility (a11y)?&lt;/li&gt;
&lt;li&gt;Why Accessibility Matters&lt;/li&gt;
&lt;li&gt;Types of Disabilities to Consider&lt;/li&gt;
&lt;li&gt;Core Principles (WCAG)&lt;/li&gt;
&lt;li&gt;Common Accessibility Mistakes&lt;/li&gt;
&lt;li&gt;Practical Implementation (Frontend + Backend)&lt;/li&gt;
&lt;li&gt;Tools for Testing Accessibility&lt;/li&gt;
&lt;li&gt;Real-World Examples&lt;/li&gt;
&lt;li&gt;Key Takeaways&lt;/li&gt;
&lt;li&gt;FAQs&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is Accessibility (a11y)?
&lt;/h2&gt;

&lt;p&gt;Accessibility (often shortened as a11y, because there are 11 letters between “a” and “y”) refers to designing applications that can be used by people with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual impairments&lt;/li&gt;
&lt;li&gt;Hearing impairments&lt;/li&gt;
&lt;li&gt;Motor disabilities&lt;/li&gt;
&lt;li&gt;Cognitive limitations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It ensures your app works with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Screen readers&lt;/li&gt;
&lt;li&gt;Keyboard-only navigation&lt;/li&gt;
&lt;li&gt;Voice controls&lt;/li&gt;
&lt;li&gt;Assistive technologies&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Accessibility Matters
&lt;/h2&gt;

&lt;p&gt;Most devs think: “My users don’t need this.”&lt;br&gt;
That’s usually wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Real Users Need It&lt;/strong&gt;&lt;br&gt;
Millions rely on assistive tech daily&lt;br&gt;
Temporary disabilities (injuries, fatigue) also matter&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Better UX for Everyone&lt;/strong&gt;&lt;br&gt;
Keyboard shortcuts = power users love it&lt;br&gt;
Proper contrast = better readability for all&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. SEO Benefits&lt;/strong&gt;&lt;br&gt;
Semantic HTML improves indexing&lt;br&gt;
Alt text improves image discoverability&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Legal Compliance&lt;/strong&gt;&lt;br&gt;
Many countries enforce accessibility standards&lt;br&gt;
Non-compliance can lead to lawsuits&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of Disabilities to Consider
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Visual&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blindness&lt;/li&gt;
&lt;li&gt;Low vision&lt;/li&gt;
&lt;li&gt;Color blindness&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hearing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deafness&lt;/li&gt;
&lt;li&gt;Hard of hearing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Motor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited hand movement&lt;/li&gt;
&lt;li&gt;Cannot use a mouse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cognitive&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dyslexia&lt;/li&gt;
&lt;li&gt;ADHD&lt;/li&gt;
&lt;li&gt;Memory issues&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“The Web is fundamentally designed to work for all people, whatever their hardware, software, language, location, or ability.” - World Wide Web Consortium (W3C)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Core Principles (WCAG)
&lt;/h2&gt;

&lt;p&gt;Accessibility is guided by WCAG (Web Content Accessibility Guidelines):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Perceivable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Users must be able to see/hear content&lt;br&gt;
 → Example: Alt text for images&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Operable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Users must be able to navigate&lt;br&gt;
 → Example: Keyboard navigation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Understandable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Content must be clear and predictable&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Robust&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Works across devices and assistive tech&lt;/p&gt;
&lt;h2&gt;
  
  
  Common Accessibility Mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Missing alt text on images&lt;/li&gt;
&lt;li&gt; Using div instead of semantic tags (button, nav)&lt;/li&gt;
&lt;li&gt; No keyboard navigation support&lt;/li&gt;
&lt;li&gt; Poor color contrast&lt;/li&gt;
&lt;li&gt; Forms without labels&lt;/li&gt;
&lt;li&gt; Auto-playing videos without controls&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Practical Implementation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Semantic HTML (Most Important)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Correct --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"submit()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Wrong --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Alt Text for Images&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"product.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Red running shoes with white sole"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Keyboard Accessibility&lt;/strong&gt;&lt;br&gt;
Ensure all interactive elements are reachable via Tab&lt;br&gt;
Use :focus styles&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. ARIA (Use Carefully)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Close menu"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;X&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rule: Don’t use ARIA if native HTML can do the job&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Forms Accessibility&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Color Contrast&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimum ratio: 4.5:1&lt;/li&gt;
&lt;li&gt;Avoid light gray text on white background&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7. Screen Reader Support&lt;/strong&gt;&lt;br&gt;
Test using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NVDA (Windows)&lt;/li&gt;
&lt;li&gt;VoiceOver (Mac)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8. Accessibility in React&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 Submit
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 Submit
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Accessibility in Laravel (Backend)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate meaningful error messages&lt;/li&gt;
&lt;li&gt;Return proper status codes&lt;/li&gt;
&lt;li&gt;Support localization (multi-language)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“Accessibility is not a feature, it is a social trend.” - Antonio Santos&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Tools for Testing Accessibility
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lighthouse (Chrome DevTools)&lt;/li&gt;
&lt;li&gt;axe DevTools&lt;/li&gt;
&lt;li&gt;WAVE&lt;/li&gt;
&lt;li&gt;Screen readers&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Example
&lt;/h2&gt;

&lt;p&gt;Imagine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user cannot use a mouse&lt;/li&gt;
&lt;li&gt;Your app has no keyboard navigation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your app is completely unusable&lt;br&gt;
That’s not a “minor bug” - that’s total failure&lt;/p&gt;

&lt;h2&gt;
  
  
  Interesting Facts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Over 1 billion people live with some form of disability. &lt;a href="https://www.who.int/news-room/fact-sheets/detail/disability-and-health" rel="noopener noreferrer"&gt;Source&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Accessibility improvements can increase conversion rates &lt;a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Accessibility/What_is_accessibility" rel="noopener noreferrer"&gt;Source&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Many accessibility fixes take less than 5 minutes&lt;/li&gt;
&lt;li&gt;Around 40.9% of color combinations on major websites still fail WCAG contrast requirements. &lt;a href="https://arxiv.org/abs/2602.24067" rel="noopener noreferrer"&gt;Source&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q1: Is accessibility only for disabled users?&lt;/strong&gt;&lt;br&gt;
No - it improves usability for everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q2: Is ARIA enough?&lt;/strong&gt;&lt;br&gt;
No - proper HTML matters more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q3: Does accessibility slow development?&lt;/strong&gt;&lt;br&gt;
Initially yes, but saves time later.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Designing for accessibility does not only benefit people with disabilities - it benefits everyone.” - Microsoft&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;Accessibility is not optional anymore.&lt;br&gt;
Modern apps must be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inclusive&lt;/li&gt;
&lt;li&gt;Usable&lt;/li&gt;
&lt;li&gt;Compliant
If your app isn’t accessible, it’s not truly “modern.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;About the Author:&lt;em&gt;Vatsal is a web developer at &lt;a href="https://www.addwebsolution.com/" rel="noopener noreferrer"&gt;AddWebSolution&lt;/a&gt;. Building web magic with Laravel, PHP, MySQL, Vue.js &amp;amp; more.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>a11y</category>
      <category>frontend</category>
      <category>react</category>
    </item>
  </channel>
</rss>
