Currently, our ASP.NET Core Web API handles both user HTTP requests and heavy Hangfire background job executions. During peak hours, CPU usage spikes heavily, degrading API response times.
Architecture Separation
We want to move the server component (job execution) into a standalone Worker Service project while keeping job creation inside the Web API project.
Web API Enqueue Setup
// Enqueuing job from API endpoint without processing local jobs
app.MapPost("/api/reports", (IBackgroundJobClient jobClient) =>
{
// Trigger background execution without running processing server locally
jobClient.Enqueue(() => Console.WriteLine("Processing report..."));
return Results.Accepted();
});What is the best practice for sharing job interfaces and contract models between the API client project and the standalone worker service? How do we ensure that the Web API project only enqueues tasks without spawning a Background Processing server instance?
Can you answer this question?
Write Answer0 Answers