Kaizen Teams

Dropdown

Table of Contents

Time to read

·

12

Published on

·

May 17, 2022

Last updated on

·

February 16, 2026

Gonzalo Curbelo, Full-Stack Developer at Kaizen Softworks

Gonzalo Curbelo

Authentic otaku

Full-Stack Developer

Scalability in ASP.NET Web APIs with Cancellation Tokens

Published on

·

February 23, 2026

Last updated on

·

February 16, 2026

Time to read

·

12

Gonzalo Curbelo, Full-Stack Developer at Kaizen Softworks

Gonzalo Curbelo

Full-Stack Developer

When dealing with high volumes of data and traffic in web application APIs, it is imperative to avoid wasting resources so that end users won’t perceive any slow downs, as well as to reduce costs in the underlying infrastructure. The topic of today’s article is to examine under what circumstances it is possible to cancel already-running HTTP requests before their completion in an API implemented with ASP.NET, and how to implement these capabilities in a few common scenarios.

Motivation

Long running HTTP requests may occur as a consequence of having to deal with an ever-increasing amount of resources for their execution, which is a scenario that can be expected in an active API serving thousands of clients per minute. Under those circumstances, having a way of knowing when the results of such requests may end up being unused would be highly desirable in order to free up server resources, such as CPU, RAM, database locks, network sockets, etc., that other clients may need to use.

Common situations where this may arise are:

  • The user starts a search but closes or navigates away from the page before the server finishes serving its results.
  • The UI client has a typeahead component that makes requests to the server and updates the results in the page as the user types, replacing old results with newer ones.

What kind of requests can and cannot be canceled?

Short lived requests that consume too little resources are better left alone, as the cost of implementing cancellation capabilities would be most surely greater than any real benefit that could be gained from that.

Requests that can have side effects, such as creating, updating, or deleting data, should also be left as they are, because there is a real risk of compromising data integrity of the system if the request is interrupted at the wrong moment, especially if there are multiple internal steps to the operation.

That leaves us only with nullipotent requests, that is, those that only fetch data but don’t modify anything after they finish, metrics and logs notwithstanding. In other words, if implemented correctly, HTTP GET requests.

Implementation

As an example, we’ll start with a basic ASP.NET controller written in C#:

using Microsoft.AspNetCore.Mvc;
namespace Kaizen.Blog.Examples.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CancellationController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get()
{
return "The endpoint was called.";
}
}

The change to allow a request to be canceled is as simple as adding a parameter with type CancellationToken to the endpoint. This type has two useful members that can be leveraged for our purposes:

  • IsCancellationRequested: Returns true if the caller asked for the request to be canceled; otherwise, false.
  • ThrowIfCancellationRequested(): Throws an OperationCanceledException if the caller asked for the request to be canceled.

With this in mind, the endpoint can be updated to handle request cancellations manually:

using System;
using System.Threading;
using Microsoft.AspNetCore.Mvc;
namespace Kaizen.Blog.Examples.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CancellationController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get(CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
return "The request was not canceled.";
}
catch (OperationCanceledException)
{
return "The request was canceled.";
}
}
}

Common Asynchronous Operations

Cancellation tokens can also be used with common asynchronous operations in web APIs. Here are some examples:

Task (System.Threading.Tasks)

// Non-cancellable version
await Task.Run(() => LongRunningSynchronousOperation());
// Cancellable version
await Task.Run(() => LongRunningSynchronousOperation(), cancellationToken);

IAsyncEnumerable (System.Linq)

var collection = GetExpensiveToCreateCollection();
// Non-cancellable version
await foreach(var item in collection)
{
// do something with item...
}
// Cancellable version
await foreach(var item in collection.WithCancellation(cancellationToken))
{
// do something with item...
}

ParallelEnumerable (System.Linq)

var collection = GetCollection();
// Non-cancellable version
var results = collection.AsParallel()
.Where(Condition)
.ToArray();
// Cancellable version
var results = collection.AsParallel().WithCancellation(cancellationToken)
.Where(Condition)
.ToArray();

IQueryable (System.Data.Entity; Entity Framework)

var usersQuery = DbContext.Users.GetAll().Where(Condition);
// Non-cancellable version
var results = usersQuery.ToList();
// Cancellable version
var results = usersQuery.ToListAsync(cancellationToken);

Dapper

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
// Non-cancellable version
var results = await connection.QueryAsync(sqlQuery);
// Cancellable version
var results = await connection.QueryAsync(
new CommandDefinition(sqlQuery,
cancellationToken: cancellationToken));

Front-End Perspective

From the front-end perspective, web client applications can cancel API calls before their completion by making use of the so-called “Abort API” (AbortController and AbortSignal). Both the standard Fetch API, as well as popular HTTP library Axios, allow canceling requests this way. An example using the former can be found in Mozilla's dom-examples repository, while usage of the later can be found in Axios Docs.

Conclusion

It should be noted that canceling long running requests in cases where they’re caused by an inefficient implementation is only a stopgap measure. It’s no substitute for a good implementation, but a way of mitigating the damage a bad one can cause. Having said that, I’ve seen situations where the cost of reimplementing an existing piece of functionality is accompanied by a high risk of breaking something, so, as a short term patch to scalability-related problems, request cancellation is a good tool to have in your arsenal.

Further reading

When dealing with high volumes of data and traffic in web application APIs, it is imperative to avoid wasting resources so that end users won’t perceive any slow downs, as well as to reduce costs in the underlying infrastructure. The topic of today’s article is to examine under what circumstances it is possible to cancel already-running HTTP requests before their completion in an API implemented with ASP.NET, and how to implement these capabilities in a few common scenarios.

Motivation

Long running HTTP requests may occur as a consequence of having to deal with an ever-increasing amount of resources for their execution, which is a scenario that can be expected in an active API serving thousands of clients per minute. Under those circumstances, having a way of knowing when the results of such requests may end up being unused would be highly desirable in order to free up server resources, such as CPU, RAM, database locks, network sockets, etc., that other clients may need to use.

Common situations where this may arise are:

  • The user starts a search but closes or navigates away from the page before the server finishes serving its results.
  • The UI client has a typeahead component that makes requests to the server and updates the results in the page as the user types, replacing old results with newer ones.

What kind of requests can and cannot be canceled?

Short lived requests that consume too little resources are better left alone, as the cost of implementing cancellation capabilities would be most surely greater than any real benefit that could be gained from that.

Requests that can have side effects, such as creating, updating, or deleting data, should also be left as they are, because there is a real risk of compromising data integrity of the system if the request is interrupted at the wrong moment, especially if there are multiple internal steps to the operation.

That leaves us only with nullipotent requests, that is, those that only fetch data but don’t modify anything after they finish, metrics and logs notwithstanding. In other words, if implemented correctly, HTTP GET requests.

Implementation

As an example, we’ll start with a basic ASP.NET controller written in C#:

using Microsoft.AspNetCore.Mvc;
namespace Kaizen.Blog.Examples.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CancellationController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get()
{
return "The endpoint was called.";
}
}

The change to allow a request to be canceled is as simple as adding a parameter with type CancellationToken to the endpoint. This type has two useful members that can be leveraged for our purposes:

  • IsCancellationRequested: Returns true if the caller asked for the request to be canceled; otherwise, false.
  • ThrowIfCancellationRequested(): Throws an OperationCanceledException if the caller asked for the request to be canceled.

With this in mind, the endpoint can be updated to handle request cancellations manually:

using System;
using System.Threading;
using Microsoft.AspNetCore.Mvc;
namespace Kaizen.Blog.Examples.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CancellationController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get(CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
return "The request was not canceled.";
}
catch (OperationCanceledException)
{
return "The request was canceled.";
}
}
}

Common Asynchronous Operations

Cancellation tokens can also be used with common asynchronous operations in web APIs. Here are some examples:

Task (System.Threading.Tasks)

// Non-cancellable version
await Task.Run(() => LongRunningSynchronousOperation());
// Cancellable version
await Task.Run(() => LongRunningSynchronousOperation(), cancellationToken);

IAsyncEnumerable (System.Linq)

var collection = GetExpensiveToCreateCollection();
// Non-cancellable version
await foreach(var item in collection)
{
// do something with item...
}
// Cancellable version
await foreach(var item in collection.WithCancellation(cancellationToken))
{
// do something with item...
}

ParallelEnumerable (System.Linq)

var collection = GetCollection();
// Non-cancellable version
var results = collection.AsParallel()
.Where(Condition)
.ToArray();
// Cancellable version
var results = collection.AsParallel().WithCancellation(cancellationToken)
.Where(Condition)
.ToArray();

IQueryable (System.Data.Entity; Entity Framework)

var usersQuery = DbContext.Users.GetAll().Where(Condition);
// Non-cancellable version
var results = usersQuery.ToList();
// Cancellable version
var results = usersQuery.ToListAsync(cancellationToken);

Dapper

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
// Non-cancellable version
var results = await connection.QueryAsync(sqlQuery);
// Cancellable version
var results = await connection.QueryAsync(
new CommandDefinition(sqlQuery,
cancellationToken: cancellationToken));

Front-End Perspective

From the front-end perspective, web client applications can cancel API calls before their completion by making use of the so-called “Abort API” (AbortController and AbortSignal). Both the standard Fetch API, as well as popular HTTP library Axios, allow canceling requests this way. An example using the former can be found in Mozilla's dom-examples repository, while usage of the later can be found in Axios Docs.

Conclusion

It should be noted that canceling long running requests in cases where they’re caused by an inefficient implementation is only a stopgap measure. It’s no substitute for a good implementation, but a way of mitigating the damage a bad one can cause. Having said that, I’ve seen situations where the cost of reimplementing an existing piece of functionality is accompanied by a high risk of breaking something, so, as a short term patch to scalability-related problems, request cancellation is a good tool to have in your arsenal.

Further reading

Related Articles

·

May 27, 2026

What AI Can and Can’t Replace in Design Systems

What happens when you build a design system from v0, Figma, and Windsurf, and let AI handle the speed while you keep the judgment.

12 read time

Read more

Just this month, I built a full design system in about 20 hours.

What used to take weeks, sometimes months, is now dramatically faster. So… what actually changed? And more importantly: what didn’t?

Design systems take time. On complex platforms, they can take hundreds of hours.

We were working with a large and complex product where inconsistencies had started to pile up. Different modules had evolved in isolation, teams were making independent decisions, and there were no shared guidelines. The answer was clear: we needed a design system.

AI tools were just starting to emerge back then. They were mostly useful for simple tasks as they tended to hallucinate when things got complex. Developers had started using them earlier than designers, MCP didn't exist yet, and Figma plugins were the best automation we had.

But the context has changed. Fast.

The Manual Era

We did what most teams did. We stopped, and we built it. Manually.

Picture two designers, a mountain of inconsistencies, and no map. We had to cross-reference information manually, digging through the code, detecting what could be merged, agreeing on naming conventions, deciding how to name components. Hours and hours of discussion until we finally landed on a solution.

In the end, we got there. A cleaner system, faster workflows, and for the first time, both teams speaking the same visual language. Hard-won, but it worked.

But now every month a new AI model seems to be released. Design is finally catching up with what developers faced about two years ago. New tools arose, and with that, the scope of our work as designers completely changed.

The Human Factor

For an internal project, I used our Kaizen site as a reference, combined with documentation from industry leaders as a guideline.

I started in v0, which is essentially a chat interface where you can generate UI components through prompts. I fed it the colors, typographies, and a reference image, and from there it was a back-and-forth: the AI generated, I reacted, adjusted, and pushed until the output matched what I had in my head. And just like that, I started prompting my way through a Design System.

Once a component was ready, I used the html.to.design plugin to bring it into Figma (yes, plugins are still alive!). Think of it as a bridge: the plugin exports designs directly from the browser into a Figma file.

Inside Figma, the intervention was more hands-on. First, I checked that everything was visually consistent with what was defined in v0: colors, typography, styles. Then I used Figma's built-in AI to rename all the component layers using BEM convention (something that would have taken a significant amount of time to do so manually).

BEM, which stands for Block Element Modifier, is a widely adopted naming convention in CSS. It structures layer names hierarchically and predictably, for example: button__label--disabled.

Using it keeps the code clean, readable, and consistent, especially when you're working alongside a developer who needs to understand what came out the other side.

Beyond naming, I also made sure the layer structure would generate the right properties when building component sets in Figma, so that all the variants would be correctly exposed and usable. My team also pointed out that adding descriptions to components and variants was key as context for any agent using them through an MCP.

The last step was connecting everything to Windsurf via MCP. With a frame selected in Dev Mode, Windsurf could read the Figma file and use the components to build more complex screens.

We worked closely with a developer throughout this phase. Not just for the technical knowledge, but because having someone who reads code fluently meant catching things we wouldn't have spotted otherwise. The design role here was direction and supervision: making sure the AI used the components correctly and didn't invent solutions where context was missing.

Every step of the process had a human decision behind it.

AI-assisted UI design workflow showing v0 component generation, html.to.design export to Figma, BEM layer organization, and Windsurf MCP development handoff.

An Unexpected Discovery

At one point, before we had any of the naming conventions figured out, I selected a frame and asked Windsurf to build a form using the components inside it, styled to match a specific card. The developer next to me was skeptical until he saw the result, and then he was just as surprised as I was.

What we realized is that the MCP wasn't reading layer names to understand context. It was reading everything inside the frame, even the loose text sitting alongside the components. Good naming is still worth doing. But the MCP doesn't need it to understand what it's looking at.

UI component library preview with cards, testimonials, service blocks, statistics, and a contact form for a modern software development website.

Learning to Talk to an AI

The more specific and contained your prompt, the better the outcome. We started with the most atomic component: the button, and worked outward from there. Each approved component became context for the next one, so the system gradually picked up the visual language we were building.

At some point I got ambitious and asked for five cards in a single prompt: blog card, service card, testimonial card, stats card, feature card… structures, states and all. The AI delivered.

Visually, everything looked fine. Then the developer looked at the code and pointed out that all five cards were independent components instead of variants of one. For a design system, that breaks everything.

One correction prompt fixed it. But it was a good reminder: the AI does exactly what you ask, not what you mean. And fixing it after the fact can cost more than getting it right from the start.

Some Things Learned Along the Way

  • Precision is key. Natural language is fine when you're asking for a cooking recipe, but when referring to a component, if you say things like "create" instead of "add", you'll probably end up with a whole new set of components instead of additional variants of an existing one.
  • The "Frame" is the context: MCPs can read everything inside the frame you select. This is a game-changer. It means the "naming conventions" debate might be shifting. If the AI understands the context visually and structurally, will we still spend hours discussing nomenclature in 2027?
  • No matter what happens, you can always roll back in less than 5 minutes and start over.
  • Work closely with a developer: they can help you understand MCPs and clear up any code-related doubts. Once you start to grasp their logic, you'll learn very quickly how to prompt in ways that AI actually understands.
  • There's nothing to lose by asking the AI to follow a specific naming convention for the code. It keeps everything clean and readable, and it takes no extra effort.
  • The AI covers roughly 80% of the work (generation, variations, exploration...), but the remaining 20% is where quality lives, and that part is not delegable. The AI executes. The judgment is still yours. And if you skip the review, you're not saving time: you'll spend it later.
  • Context matters more than tooling. What you don't define, the AI will invent. Small components may be resolved well, but large interfaces require more definition from the start. A well-defined system scales. An undefined one generates inconsistencies faster than you can fix them.
  • Figma is no longer the mandatory starting point. It's useful as a visual reference, a QA space, or a consolidation layer. But the AI doesn't need it. We still do.
  • There's no single right workflow yet. What you do depends on the project. We're in a transition moment where the tools change faster than the standards. The best thing you can do right now is experiment.

What AI Still Can’t Replace

Through all of this, a few things became very clear. These are the parts that didn’t change:

  • Knowing when something looks off. The AI generates, but it doesn't notice when the result doesn't feel right. That eye is yours.
  • Direction and supervision. The AI used the components we gave it, but without someone supervising it, it invents solutions where there is no context to work from.
  • The definition of done is still a human call, whether it's a conversation with a PO, a stakeholder, or just the designer's criteria. There's no prompt for that.
  • The context: knowing why certain decisions matter, what a component should communicate, what the user will actually feel. Business knowledge, stakeholder dynamics, unwritten rules, empathy for the end user. These take years to build and live in the people doing the work, not in the tools they use.

My Two Cents

The tools changed, and that gave me the chills, but throughout this experience I found that the designer's role is more alive than ever.

What once took a team weeks can now be prototyped in hours. That’s not a threat; it’s an invitation to get curious.

I'm still figuring a lot of this out, and I suspect most of us are. There's no right workflow yet, and honestly, that's fine. We are in a transition where tools change faster than standards. The best thing you can do is experiment. Don't wait for a "definitive" workflow, it might be obsolete by next month.

Go ahead, try prompting your way through a component. You might be surprised how fast the system starts to take shape.

·

May 15, 2026

Can AI Safely Apply Changes Across Microservices?

AI can update microservices safely, but only when it understands the system’s architecture, ownership, and service relationships.

12 read time

Read more

Applying changes across microservices is difficult because business logic is distributed across multiple services, each with its own data, contracts, and responsibilities.

In our experiment at Kaizen Softworks, we tested whether an AI system could safely apply coordinated changes across a microservices architecture using only minimal input.

Short answer: Yes, but only when the AI has enough architectural context.

Why are coordinated changes in microservices so hard?

In distributed systems, a single business change rarely affects just one service.

It often requires:

  • Updating multiple microservices
  • Modifying message contracts
  • Keeping DTOs (Data Transfer Objects) consistent
  • Respecting domain boundaries defined by Domain-Driven Design (DDD)

Key entities in this system:

  • Microservice: An independently deployable service responsible for a specific domain
  • Aggregate (DDD): A cluster of domain objects treated as a single unit
  • DTO (Data Transfer Object): A structured format used to transfer data between services
  • Message/Event: A communication mechanism between services

The complexity is not in the code, it’s in the relationships between components.

The experiment: Can AI reason across services with minimal input?

We designed a controlled experiment to test whether an AI model could apply system-wide changes with limited information.

Input given to the AI:

  • Message definitions (events between services)
  • DTOs (data contracts)

Tasks the AI had to perform:

  1. Identify affected aggregates
  2. Determine service ownership
  3. Apply coordinated changes across services
  4. Maintain consistency in messages and DTOs

In other words, the AI had to behave like a software architect, not just a code generator.

What was the biggest obstacle?

The biggest challenge was not technical, it was contextual.

Before and after diagram showing how ambiguous microservice names prevent AI from understanding service ownership, while aggregate-to-service mapping helps AI apply safe coordinated changes.

Problem: unclear service naming

Instead of descriptive names like:

  • order-service
  • billing-service

Our services were named:

  • john
  • sally
  • roger

This removed any semantic clues about responsibility.

Result: The AI could not infer which service owned which domain logic.

The missing piece: aggregate ownership mapping

To solve this, we introduced a simple but powerful structure:

Aggregate → Service mapping

  • Order → john
  • Shipment → sally
  • Invoice → roger

This created a clear relationship between domain concepts and system components.

Once ownership was explicit, the architecture became understandable.

How we used AI to generate architectural context

Instead of building this mapping manually, we used AI to analyze the codebase and extract:

  • Where each aggregate was defined
  • Which microservice implemented it
  • The relationship between domain and infrastructure

The result was a machine-readable architecture map.

In practice, we used AI to generate the context that AI itself needed.

Results: Can AI safely apply distributed changes?

With the architecture map in place, the AI was able to:

  • Trace message flows across services
  • Identify affected aggregates
  • Locate the correct microservices
  • Apply coordinated updates
  • Maintain consistency between DTOs and messages

While not perfect, the system worked reliably as a proof of concept.

What is the real limitation of AI in microservices?

The main limitation of AI is not code generation, it’s architectural understanding.

Without knowing:

  • Which components exist
  • How they relate
  • Who owns what

AI cannot safely modify a distributed system.

AI performance depends more on context quality than model capability.

When can AI safely modify microservices?

AI works well when:

  • Aggregate ownership is clearly defined
  • Message contracts are explicit
  • Architecture is structured and consistent

AI struggles when:

  • Naming is ambiguous
  • Relationships are implicit
  • Context is incomplete

Simple rule: If the architecture is clear, AI can reason. If not, it guesses.

Final thoughts

This experiment revealed something important:

AI doesn’t fail because it can’t write code.
It fails because it can’t see the system.

As teams move toward AI-assisted development, the focus will likely shift from:

Writing better code to Designing better systems for machines to understand

At Kaizen Softworks, we see this as a foundational shift.

Because when AI can understand architecture, it doesn’t just generate code, it helps evolve systems.