Validation is usually introduced as a simple check: make sure a required field is present, confirm a value is in the correct range, and reject invalid input before it reaches the application logic.
That works well for local validation.
The situation changes when validation needs to call a database, an external service, or another asynchronous resource. Examples include checking whether an email address already exists, verifying a customer against another system, or checking whether a referenced record is still active.
These operations are naturally asynchronous because they involve I/O.
The challenge is that ASP.NET Core request validation is often designed around synchronous validation APIs. If asynchronous work is forced into a synchronous validation path, developers can end up blocking threads, creating unnecessary latency, or introducing difficult-to-debug behavior.
A better approach is to separate local validation from asynchronous business validation and execute the latter as part of the request pipeline.
Why Asynchronous Validation Is Different
Consider a request for creating a customer:
public record CreateCustomerRequest(
string Name,
string Email);
Checking whether the email has a valid format is local work:
Email format
|
v
Local validation
|
v
No I/O required
Checking whether the email already exists in the database is different:
Email
|
v
Database query
|
v
Await database response
|
v
Validation result
The second operation is asynchronous because the application has to wait for an external resource.
This distinction is important when designing validation.
Synchronous Validation vs Asynchronous Validation
The two types of validation serve different purposes.
Validation type | Example | I/O required | Async |
|---|
Required field | Name must exist | No | No |
String length | Name must be under 100 characters | No | No |
Numeric range | Price must be positive | No | No |
Email format | Valid email syntax | No | No |
Database uniqueness | Email must not already exist | Yes | Yes |
External verification | Customer exists in another system | Yes | Yes |
Inventory check | Product is currently available | Yes | Yes |
Local validation should remain simple and fast.
I/O-based validation should be handled asynchronously.
The Problem With Blocking Async Work
A common mistake is trying to turn asynchronous database work into synchronous validation.
For example:
var exists = repository.ExistsAsync(email).Result;
or:
var exists = repository.ExistsAsync(email).GetAwaiter().GetResult();
This defeats the purpose of asynchronous programming.
The request thread is blocked while the database operation is running.
Under higher concurrency, this can become expensive:
Request 1 -> blocked waiting for DB
Request 2 -> blocked waiting for DB
Request 3 -> blocked waiting for DB
Request 4 -> blocked waiting for DB
The database may be responding normally, but the application can still experience thread pressure.
Async I/O should remain async from the validation layer through the data-access layer.
Keep Data Annotation Validation Synchronous
Data annotations are useful for basic request validation.
For example:
public record CreateCustomerRequest(
[property: Required]
[property: StringLength(100)]
string Name,
[property: Required]
[property: EmailAddress]
string Email);
These rules do not need a database.
They are ideal for immediate validation.
The application can then perform asynchronous business validation after basic model validation succeeds.
Moving Database Validation Into the Application Layer
Consider a customer service:
public interface ICustomerService
{
Task<bool> EmailExistsAsync(
string email,
CancellationToken cancellationToken);
}
The implementation can use Entity Framework Core:
public sealed class CustomerService(
AppDbContext db) : ICustomerService
{
public Task<bool> EmailExistsAsync(
string email,
CancellationToken cancellationToken)
{
return db.Customers
.AnyAsync(
x => x.Email == email,
cancellationToken);
}
}
Now the asynchronous operation stays asynchronous.
The API endpoint can perform the business validation:
app.MapPost("/api/customers",
async (
CreateCustomerRequest request,
ICustomerService service,
CancellationToken cancellationToken) =>
{
if (await service.EmailExistsAsync(
request.Email,
cancellationToken))
{
return Results.Conflict(
new
{
Message = "A customer with this email already exists."
});
}
return Results.Ok();
});
The important part is:
await service.EmailExistsAsync(
request.Email,
cancellationToken);
The request thread is not synchronously blocked while the database operation executes.
Validation Should Happen at the Right Layer
A useful validation structure is:
HTTP Request
|
v
Basic input validation
|
v
Application validation
|
v
Business rules
|
v
Database
Each layer has a different responsibility.
Basic validation answers:
"Is this request structurally valid?"
Application validation answers:
"Can this request be processed?"
Business validation answers:
"Does this operation violate a business rule?"
This separation keeps validation logic easier to test and maintain.
Using a Dedicated Async Validator
For larger applications, asynchronous validation can be moved into a dedicated component.
For example:
public interface IAsyncValidator<T>
{
Task<IReadOnlyList<string>> ValidateAsync(
T request,
CancellationToken cancellationToken);
}
An implementation could check database rules:
public sealed class CreateCustomerValidator(
AppDbContext db)
: IAsyncValidator<CreateCustomerRequest>
{
public async Task<IReadOnlyList<string>> ValidateAsync(
CreateCustomerRequest request,
CancellationToken cancellationToken)
{
var errors = new List<string>();
if (await db.Customers.AnyAsync(
x => x.Email == request.Email,
cancellationToken))
{
errors.Add("Email is already registered.");
}
return errors;
}
}
The endpoint can then use the validator:
app.MapPost("/api/customers",
async (
CreateCustomerRequest request,
IAsyncValidator<CreateCustomerRequest> validator,
CancellationToken cancellationToken) =>
{
var errors = await validator.ValidateAsync(
request,
cancellationToken);
if (errors.Count > 0)
{
return Results.ValidationProblem(
errors.ToDictionary(
key => "Request",
value => errors.ToArray()));
}
return Results.Ok();
});
This approach becomes useful when multiple endpoints need similar validation behavior.
FluentValidation and Async Rules
Applications using FluentValidation can define asynchronous validation rules directly.
A validator can look conceptually like this:
public sealed class CreateCustomerValidator
: AbstractValidator<CreateCustomerRequest>
{
public CreateCustomerValidator(
AppDbContext db)
{
RuleFor(x => x.Email)
.NotEmpty()
.EmailAddress();
RuleFor(x => x.Email)
.MustAsync(async (email, cancellationToken) =>
!await db.Customers.AnyAsync(
x => x.Email == email,
cancellationToken))
.WithMessage("Email is already registered.");
}
}
The important distinction is that the asynchronous rule must execute through an asynchronous validation call.
The application should not call a synchronous validation method and expect it to safely execute asynchronous rules.
For example, the validation flow should be asynchronous:
var result = await validator.ValidateAsync(
request,
cancellationToken);
rather than forcing asynchronous validation through a synchronous API.
Cancellation Matters
Asynchronous validation often involves database or network calls.
Those operations should accept the request cancellation token.
For example:
await db.Customers.AnyAsync(
x => x.Email == email,
cancellationToken);
If the client disconnects before validation completes, cancellation can prevent unnecessary work.
The flow becomes:
Client disconnects
|
v
Request cancellation
|
v
CancellationToken
|
v
Database operation
|
v
Operation cancelled
This becomes particularly useful when validation involves multiple external resources.
Avoid Multiple Unnecessary Database Queries
Async validation can accidentally create an N+1-style validation problem.
Consider a request containing several products:
public record OrderRequest(
IReadOnlyList<OrderItemRequest> Items);
public record OrderItemRequest(
int ProductId,
int Quantity);
Performing one database query per item can become expensive:
Product 1 -> DB query
Product 2 -> DB query
Product 3 -> DB query
Product 4 -> DB query
Instead, collect the IDs and query them together:
var productIds = request.Items
.Select(x => x.ProductId)
.Distinct()
.ToArray();
var existingIds = await db.Products
.Where(x => productIds.Contains(x.Id))
.Select(x => x.Id)
.ToListAsync(cancellationToken);
Now the validation process can compare the request against one result set.
Async does not automatically mean efficient. Query design still matters.
Validation and Concurrency
A database uniqueness check has an important limitation.
Suppose the application performs:
Check email
|
v
Email does not exist
|
v
Insert customer
Another request can insert the same email between those operations.
Therefore, application-level asynchronous validation should not replace database constraints.
The database should enforce uniqueness:
modelBuilder.Entity<Customer>()
.HasIndex(x => x.Email)
.IsUnique();
The application-level check improves the user experience by detecting common conflicts early.
The database constraint provides the final guarantee.
Handling Validation Races
Even when you check asynchronously before inserting, you should still handle database constraint violations.
The correct architecture is:
Async validation
|
v
Friendly early error
|
v
Database constraint
|
v
Final protection
This is especially important in high-concurrency applications.
Validation is not a substitute for transactional consistency.
Async Validation and External APIs
Some validation rules require another service.
For example:
Create Order
|
v
Validate Customer
|
v
Customer Service
|
v
Validate Inventory
|
v
Inventory Service
|
v
Create Order
These calls should also use asynchronous APIs:
var customer = await customerClient.GetCustomerAsync(
request.CustomerId,
cancellationToken);
var inventory = await inventoryClient.CheckAvailabilityAsync(
request.Items,
cancellationToken);
Avoid sequential calls when they are independent.
If two validations do not depend on each other, they can sometimes run concurrently:
var customerTask = customerClient.GetCustomerAsync(
request.CustomerId,
cancellationToken);
var inventoryTask = inventoryClient.CheckAvailabilityAsync(
request.Items,
cancellationToken);
await Task.WhenAll(
customerTask,
inventoryTask);
This can reduce overall validation latency.
Use this pattern carefully when external services, rate limits, or database connections are involved.
Common Mistakes
Calling .Result or .Wait()
Blocking an asynchronous operation creates unnecessary thread usage and can introduce deadlock problems in some execution environments.
Performing Database Validation Inside Simple Attributes
Attributes are a poor place for database-dependent business rules because they are primarily designed for metadata-driven synchronous validation.
Treating Validation as a Security Boundary
Validation improves correctness but does not replace authorization, database constraints, or transactional protections.
Running Too Many Validation Queries
Multiple independent database calls can turn a simple request into a slow operation.
Batch queries where practical.
Forgetting Cancellation
Long-running database and external-service validation should generally receive the request cancellation token.
Assuming Async Means Faster
Async improves resource utilization during I/O waits. It does not make the database query itself faster.
Best Practices
Keep Cheap Validation Synchronous
Use local validation for:
Required fields
String length
Format checks
Numeric ranges
Basic structural rules
Keep I/O-Based Validation Asynchronous
Use asynchronous application or domain services for:
Enforce Critical Rules at the Database
Unique values, referential integrity, and transactional consistency should be protected by the database where appropriate.
Pass Cancellation Tokens
Propagate the request cancellation token through validation, repositories, EF Core queries, and external API clients.
Validate Once
Avoid repeating the same database or network validation in multiple application layers.
Advantages
Avoids blocking threads during I/O.
Works naturally with database and HTTP calls.
Improves scalability under concurrent requests.
Makes business validation easier to isolate and test.
Supports cancellation.
Allows independent validation operations to run concurrently.
Disadvantages
Adds asynchronous control flow.
Database or external-service validation increases request latency.
Poorly designed validators can generate excessive queries.
External validation introduces service availability dependencies.
Async validation still requires database constraints for concurrency safety.
Troubleshooting Checklist
If asynchronous validation is causing performance or correctness problems, check:
Are any .Result, .Wait(), or .GetAwaiter().GetResult() calls present?
Is the validator actually being executed asynchronously?
Are database queries using CancellationToken?
Are multiple validation queries being executed unnecessarily?
Can independent external validations run concurrently?
Are critical uniqueness rules also enforced by the database?
Are external service timeouts configured?
Is validation happening in the correct application layer?
Are validation errors being returned consistently?
Are you measuring database time separately from application validation time?
A Practical Validation Pipeline
A production API can keep the validation flow simple:
HTTP Request
|
v
Model binding
|
v
Synchronous input validation
|
v
Asynchronous business validation
|
v
Authorization
|
v
Application operation
|
v
Database transaction
The exact ordering can vary based on the application, but the important principle is to avoid putting every kind of validation into one mechanism.
Local validation should be cheap.
I/O-based validation should be asynchronous.
Data integrity should ultimately be protected where the data lives.
Summary
Asynchronous validation becomes important when validation needs to access a database, call another service, or perform any other I/O operation.
The safest design is to keep simple structural validation synchronous and move database or network-dependent rules into an asynchronous application layer.
ASP.NET Core applications can use dedicated async validators, application services, or validation libraries that support asynchronous rules. Regardless of the approach, avoid blocking async operations with .Result or .Wait().
Cancellation tokens should flow through database and external-service calls, and independent checks can sometimes run concurrently to reduce latency.
Most importantly, asynchronous validation should not be treated as the final guarantee for data integrity. Application checks can improve error messages and user experience, while database constraints and transactional rules provide the protection required under concurrent requests.
Join the conversation! Your thoughts help the community grow.