Backend optimization tricks & techniques
How I reduced API response time from 8-10s to under 2s — Backend optimization tricks I personally use One of our payment endpoints was doing ALL of this synchronously:
✦ Updating database records
✦ Sending in-app & push notifications to host, vendor & admin
✦ Sending email alerts to all related entities
The result? 8-10 second response times. Users were frustrated.
Here's exactly how I fixed it 👇
1️⃣ Validate on the Frontend First Don't let invalid data hit your server at all. In our case — images above 5MB, videos above 50MB, unsupported formats (.svg, .gif, non-browser-compatible video) — all rejected before the request is even made.
Less wasted server processing = faster responses.
2️⃣ Upload Media in Parallel, Not Sequentially If you're uploading multiple files, don't await them one by one. Use Promise.all() — run all uploads simultaneously and wait for them together.
Simple change. Massive time saving.
3️⃣ Return the Response First — Do the Rest in the Background This was the biggest win for us. The user only NEEDS to know the payment succeeded. They don't need to wait for emails and notifications to send.
So now we: → Complete critical DB operations → Return the response immediately → Fire notifications asynchronously in the background Response time dropped dramatically. Users felt the difference instantly.
4️⃣ Use Database Indexing — But Carefully Indexing speeds up READ queries on frequently queried columns (like a custom ID field). But here's what most devs miss: ⚠️ Every indexed column creates a BSON tree that must be maintained on every write (insert, update, delete). So unnecessary indexing actually slows down your write operations. Rules I follow: → Index columns you frequently filter/search by → Skip _id and unique fields like email — already indexed by default → Understand the tradeoff before applying
5️⃣ Only Select the Fields You Actually Need When Populating If you're joining/populating another collection, don't pull the entire document. Need to verify a vendor's bank account is linked? Just select stripeConnectedAccountId — not the whole bank account document.
.populate('bankAccount', 'stripeConnectedAccountId')
Less data transferred = faster queries.
These 5 optimizations took our slowest endpoints from 8-10s → under 2s. No infrastructure changes. No new tools. Just smarter code.
💡 Which of these do you already use? Drop a comment 👇
♻️ Repost if this helped someone on your network.