Scrivio Interview library
ScenarioPrincipal7 min read · updated 12 November 2026

A production incident shows customer data leaked between requests because a singleton bean cached the last user. How would you respond as the senior technical leader, both immediately and over the next year?

Immediately, I would stop the leak by deploying a fix, treat it as a security and privacy incident, find out exactly which customers' data went to whom and for how long, and follow the company's incident and disclosure process with legal and privacy teams. Then I would search every codebase for the same pattern of mutable state in singletons. Over the next year, I would add automated checks and concurrent-request tests, run a blameless review whose lessons reach every team, and track each follow-up action to completion.

Why this question is asked

A bug that returns one customer's data to another is no longer a technical curiosity; it is a data breach, with legal duties, deadlines and customer trust at stake. Interviewers ask this of very senior people to see two things at once: whether we can lead the first hours calmly and in the right order, and whether we can turn one painful incident into lasting change across an organisation. In this answer, we will recap the technical cause, walk through the immediate response hour by hour, then look at the search for similar bugs, the automated prevention, the blameless review and the follow-through over the following year.

1A Quick Recap of the Technical Cause

Spring beans are singletons by default: one instance serves every request thread. If a service stores the current user in a field, for example to avoid passing it around, then request A writes Alice into the field, request B writes Bob, and request A reads Bob before it builds its response. Alice receives Bob's account details. The same happens when a singleton caches the last loaded customer and returns it without checking the key properly.

The bug passes tests because tests run one request at a time, and it appears only when requests overlap, which in production can be thousands of times a day. That matters for the response: the exposure may be much wider than the one report that brought it to our attention.

2The First Hours: Contain, Assess, Communicate

The first goal is to stop further exposure. If a fix is small and obvious, such as turning the field into a local variable, we ship it through an expedited but still reviewed change. If it is not, we contain the damage another way: disable the feature with a flag, route traffic away from the affected endpoint, or in the worst case take that part of the service offline. A few hours of reduced service is far cheaper than continued leaking.

At the same time we open a formal incident with a named incident commander, so that one person coordinates and the engineers who fix the bug are not also answering every question. Because personal data was exposed, the security and privacy teams and legal counsel join immediately. Regulations such as GDPR can require notifying the authority within 72 hours of becoming aware of a breach, and contracts may require telling enterprise customers, so the clock starts now, not after the fix.

Step throughImmediate response to a cross-request data leak
  1. Leak reportedone customer saw another's data
  2. Open incidentincident commander, security, privacy, legal
  3. Is a small, safe fix ready?
    YesShip the reviewed fixNoDisable the feature or route traffic away
  4. Preserve logs and tracesbefore retention removes them
  5. Assess scopetime window, endpoints, affected customers
  6. Disclosure decisionlegal and privacy, within regulatory deadlines
  7. Notify customers and regulatorsas the process requires

7 steps in order. Play them, or step through them one at a time.

Containment and evidence come first; disclosure follows the company's process.

Next we assess scope. We need to know when the bad code was deployed, which endpoints and services used the bean, how many requests overlapped in that time, and ideally which customers saw which other customers' data. Access logs, trace IDs and response logs can often reconstruct this: if a response carried a customer ID that does not match the authenticated user, that is a confirmed exposure. We preserve these logs before retention policies delete them. The legal and privacy teams decide on disclosure based on what we find; our job is to give them accurate facts quickly and to be clear about what we do not yet know.

3Search for the Same Bug Elsewhere

One bug of this kind usually means the pattern exists elsewhere, because the author learned it somewhere or copied it. Before closing the incident, we search all services for mutable instance fields in Spring beans. A quick ArchUnit test run across every repository, or a simpler code search for non-final fields in classes annotated with @Service, @Component and @RestController, produces a list in a day. We also look for ThreadLocal values that are set but not cleared, which leak data between requests on pooled threads in the same way.

Each finding gets triaged by risk. A field that holds user or tenant data in a service handling personal information is fixed this week; a non-final logger reference is a cleanup. This turns one fix into an organisation-wide sweep and tells us whether the incident was a one-off or a symptom.

4Prevention Over the Next Year

The sweep fixes today's code; prevention protects tomorrow's. We add automated checks to the shared build: ArchUnit rules that fail on non-final fields in singleton beans and on known unsafe types, shipped in the company's service starter so new services get them for free. We add a concurrent-request test pattern for any endpoint that returns personal data: hundreds of parallel requests, each authenticated as a different test user, each checked to receive only its own data. That one test would have caught this incident before release.

We also add a runtime safeguard where it is cheap: a response filter or test-environment assertion that checks the customer ID in sensitive responses matches the authenticated principal, and logs loudly when it does not. Defence in depth means we do not rely on code being perfect.

5A Blameless Review and Shared Lessons

Within a week or two we run a blameless post-incident review. Blameless means we ask how our system of tools, reviews and training allowed a reasonable engineer to ship this, not who made the mistake. If people fear blame, they hide near misses, and near misses are how we learn cheaply. The review produces a timeline, the contributing factors (no rule against mutable fields, no concurrent tests, a reviewer unfamiliar with the pattern) and a short list of actions with owners and dates.

Then we share the lesson widely: a short write-up across engineering, a session in the architecture forum, and a worked example added to onboarding so every new engineer sees this exact bug and its fix in their first weeks.

6Tracking Actions to Completion

Post-incident actions often die quietly once the urgency fades. So each action goes into the normal tracker with an owner and a due date, and I review progress monthly with the engineering leads until all are done. For the year, I would also watch outcome measures: violations found by the new rules, the number of services with concurrent-request tests on sensitive endpoints, and whether any similar incident recurs. After a quarter, a short follow-up review checks that the actions really changed behaviour rather than just closing tickets.

7Follow-up questions

Would you roll back or roll forward?

Whichever stops the leak fastest and most safely. If the bug arrived in a recent deployment and the previous version is known to be good, rolling back is often quickest. If the bug is old, rolling back does not help, so we roll forward with a small, reviewed fix or disable the feature. The decision is about speed of containment with low risk, not pride.

How do you balance speed of disclosure against accuracy?

We follow the legal and privacy teams' lead, because the deadlines are set by regulation and contracts. Our role is to give them the best facts we have at each point, clearly marked as confirmed or estimated, so they can notify on time and update later if the scope changes.

What would you tell the engineer who wrote the bug?

That the system let them down as much as they let it down, and that we need their knowledge of the code to fix and assess it. Blame makes people defensive and slower, while their help is the fastest route to understanding the scope.

8Conclusion

In this answer, we treated a cross-request data leak from a singleton as both a bug and a breach. Immediately, we contain it with a fix or a feature switch, open a formal incident with security, privacy and legal, preserve evidence, assess exactly who was exposed, and follow the disclosure process within its deadlines. Then we sweep every codebase for the same pattern. Over the year, we add build checks and concurrent-request tests, run a blameless review whose lessons reach every team, and track each action until it is done.

What to say in the interviewAbout 90 seconds aloud

Open with

I would treat it first as a data breach, not just a bug. In the first hour the priority is stopping further exposure: if the fix is small and obvious, like moving the cached user into a local variable, we ship it through an expedited but reviewed change; otherwise we disable the feature or route traffic away.

Then, if they want more

In parallel I would open a formal incident with an incident commander and bring in security, privacy and legal straight away, because regulations like GDPR can require notification within 72 hours. Then we assess scope: when the code was deployed, which endpoints used the bean, and from logs and traces which customers received someone else's data.

We preserve those logs before retention removes them, and we give legal accurate facts so they can decide on disclosure. Before closing the incident I would search every service for mutable fields in singleton beans and uncleared ThreadLocals, because one instance of the pattern usually means more.

Over the next year, I would put ArchUnit rules into the shared service starter, require concurrent-request tests for endpoints returning personal data, run a blameless review focused on what in our process let this through, share the lessons through write-ups and onboarding, and personally track every follow-up action to completion with monthly reviews.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A production incident shows customer data leaked between requests because a singleton...": https://scrivio-interview-library.netlify.app/spring-boot/bean-scopes/63990c066e/