TLDR: Stop making your users wait for things that don’t matter right now.
I hate waiting. If I click “Save” on a profile page, I want it to save. I don’t want to wait 5 seconds because the backend is busy trying to calculate loyalty points, sync with the ERP, and send a “Welcome” email to my grandmother.
In a production environment, putting everything in the request pipeline is a recipe for disaster. If the ERP is down, the user can’t save their profile? That’s just bad design.
Enter “The Chores” Pattern
We solved this by splitting our responsibilities. The API is for User Interaction. It should be blazing fast. Anything else? That’s a Chore.
Chores are background tasks. They need to happen, but they can happen 5 seconds later, or even—god forbid—at 3 AM.
Real-World Example: Syncing Exchange Rates
In our logistics system, we need fresh exchange rates. But querying an external API every time we generate a quote is slow and expensive.
So, I built a dedicated Azure Function app just for these maintenance tasks. We call it MyProject.Chores.Function (creative, I know).
Here is a simplified look at how we implemented a daily sync using a Timer Trigger:
|
|
Why this wins
- Resilience: If the currency provider goes down, my API doesn’t care. We just use yesterday’s rates. It’s better than crashing.
- Performance: My API endpoints are not blocked by external HTTP calls.
- Peace of mind: I know that “dirty jobs” are handled by the “Chores” function.
We’ve since expanded this to handle everything from cleaning up old logs to generating PDF reports. If it’s not urgent, it’s a Chore.