Skip to content

Navid's Blog

Ideas, Experiments, and Lessons Learned

Menu
Menu

That Time My API Returned Wrong Data for 3 Hours

Posted on March 5, 2026 by Navid

It was a regular Tuesday. I deployed a small change to our user API — just a minor refactor to clean up some duplicate code. Three hours later, my phone started buzzing. Customers were seeing wrong profile data.

The Symptom

Support tickets started flooding in: “Why is my email showing as someone else’s?” Users were seeing each other’s information. Not all of them — just some. That made it worse because we couldn’t reproduce it reliably at first.

The Investigation

I rolled back immediately. The problem stopped. Good. But I needed to know what went wrong.

I spent the next hour staring at my code. The change was simple — I extracted a helper function to format user data. Here’s what I wrote:

function formatUser(user) {
  return {
    name: user.name,
    email: user.email,
    id: user.id
  };
}

And here’s how I was calling it:

const user = getUserFromDb(userId);
const formatted = formatUser(user);
// ... later in the code
console.log(user.email); // wrong!

The Root Cause

JavaScript objects are passed by reference. My formatUser function wasn’t creating a new object — it was mutating the original user object. When multiple requests came in simultaneously, they were sharing the same object in memory.

I fixed it by spreading the object:

function formatUser(user) {
  return {
    ...user,
    name: user.name,
    email: user.email,
    id: user.id
  };
}

What I Learned

  • Always create new objects in functions that claim to “format” or “transform” data
  • Test concurrent requests — this bug only appeared under load
  • Use Object.freeze() if you want to catch accidental mutations early

The fix took 30 seconds. The debugging took 3 hours. That’s usually how it goes.

Categories

  • AI Experiments
  • Coding
  • Debugging Stories
  • Hot Takes
  • Ideas
  • Lessons Learned
  • Project Management
  • Uncategorized
  • Vibe Coding

Recent Posts

  • How I Handled My First Production Outage (And What I Learned)
  • I Finally Fixed Our Slow Database Queries — Here’s What Actually Worked
  • I Finally Fixed Our Slow Database Queries — Here’s What Actually Worked
  • Why I Stopped Using Microservices for Small Projects
  • I Gave AI Full Access to Our Production Database. Here’s What Happened