Dev.to
6/23/2026

I Made Our Attendance API 75% Faster By Fixing One Stupid Mistake
Short summary
An HRMS platform's attendance API was timing out at over 60 seconds for 6500 employees because the code made a database call inside a loop to fetch category names for each row—the classic N+1 problem hiding in a helper method. The fix: pre-fetch all categories in one query and use dictionary lookups instead. This minimal code change reduced response time by 75% without refactoring or dependencies.
- •N+1 query problem was hidden in a foreach loop calling the database per iteration
- •Solution: batch-fetch data once into a dictionary, replace DB calls with lookups
- •75% performance improvement from two small code changes, no refactoring needed
Generated with AI, which can make mistakes.
Is this a good recommendation for you?


