Scenario-Based Technical Interview Questions
Scenario-based questions describe a situation, such as a slow endpoint or a failing job, and ask what you would do. They test how you think under ambiguity. There is rarely one right answer, so the structure of your answer matters as much as the content.
The examples below use backend and Java settings, but the method applies to any stack.
A structure for answering
- Clarify: ask about scale, impact, recent changes and what is already known.
- Gather evidence: logs, metrics, traces, dumps. Say what you would look at first and why.
- Form hypotheses and rank them by likelihood and cost to check.
- Mitigate first if users are affected (roll back, scale, disable a feature), then fix the root cause.
- Verify the fix and describe how you would prevent a repeat (alerts, tests, runbook).
Example scenarios and approaches
Scenario: an API endpoint became slow after a release. What do you do?
Check whether the slowdown correlates with the deploy and roll back if impact is high. Use traces or logs to find which layer is slow: the database (slow or missing-index queries, N+1), a downstream call, connection pool exhaustion, or GC pauses. Reproduce with a profile or load test, fix the measured bottleneck and add a metric or alert.
Scenario: customers were charged twice because of a client retry. How do you prevent it?
Make the payment endpoint idempotent. Require an idempotency key from the client, store the key with the result, and return the stored result for repeats. Back it with a unique constraint so concurrent duplicates cannot both succeed.
Scenario: a service restarts repeatedly with OutOfMemoryError.
Capture a heap dump on OOM and review GC logs. Look at the largest retained objects: unbounded caches, large result sets loaded into memory, leaked sessions or ThreadLocals. Fix the retention (bounds, pagination, eviction) rather than only raising -Xmx, and add heap metrics.
Scenario: requests hang and CPU is low. What could be happening?
Suspect blocked threads. Take several thread dumps a few seconds apart and look for threads waiting on the same lock, exhausted connection pools, or a deadlock. Then fix lock ordering, add timeouts, or size the pool correctly.
Scenario: you must import a multi-million-row CSV file without crashing the service.
Stream the file instead of loading it whole, process in batches (for example batch inserts), commit per batch so progress is not lost, make the job restartable and idempotent, and report progress and rejected rows. Run it as a background job so it does not block request threads.
Scenario: a cache entry expires and a thousand requests hit the database at once.
That is a cache stampede. Allow only one caller to recompute a missing entry (request coalescing or a lock), add jitter to expiry times, or refresh entries before they expire.
Scenario: traffic suddenly grows tenfold. How do you protect the system?
Find the bottleneck first. Then apply the relevant measures: rate limiting and load shedding at the edge, caching reads, scaling stateless services horizontally, putting slow work behind a queue, and protecting the database with connection limits. Test the plan with a load test.
Scenario: two services must stay consistent but cannot share a transaction.
Use a saga with compensating actions or the transactional outbox with idempotent consumers, and accept eventual consistency. Explain what the user sees while the process is in flight.
Practice this on Quick Tech Learners
Reading answers is only the first step. Quick Tech Learners lets you turn scenario thinking into active practice once you create an account and sign in.
- Interview Insights: browse interview questions shared by the community and filter them by topic tag.
- Practice Quiz: choose the concepts you want to revise, answer questions, and review how you did.
- Coding Practice: write and run code in a browser editor against test cases. Pick a language, a difficulty band from Beginner to Expert, and either Practice mode (with hints) or Interview mode.
- Study Plan and reports: set the topics you are preparing, then check performance, mastery and readiness reports to see where the gaps are.
- Share Interview Question: add a question you were asked so other learners can practise it.