The 30 second answer
First I get the real failing request from production: the status code, the error log and the trace for that request ID. Then I compare the two environments, because the code is the same and something around it differs. The usual causes are configuration and secrets, a different Spring profile, dependency or JDK versions, network access, DNS or TLS to a downstream, permissions, timeouts, and real data volume or shape. I fix the difference and add a check so it can't drift again.
Start from evidence in production, not from guesses on my laptop. I find one failing request and follow it: the HTTP status, the error log with its stack trace, and the distributed trace or correlation ID that shows which hop failed. A 4xx usually means the request or auth differs; a 5xx with a stack trace points at the service; a timeout points at a downstream or the network. I also check whether it fails for every request or only some users, regions, pods or payloads. "Only some" usually means data or one bad instance.
Then diff the environments. The same code behaves differently because the things around it are different. The Twelve-Factor App calls this dev/prod parity and recommends keeping development, staging and production as similar as possible, including the same kinds of backing services. I check these in order:
- Configuration and secrets. Spring Boot reads properties from many sources in a fixed order, and environment variables and command-line arguments override
application.yml. A missing or overridden variable, a wrong active profile, or a secret that exists on my machine but not in the cluster is the most common cause. The Actuatorenvandconfigpropsendpoints, protected and with values masked, show what the running app actually resolved. - Versions. A different JDK, a different library version pulled in by the build, or a different container base image. I compare the image digest and the dependency tree with what I ran locally.
- Network and downstreams. Locally I may call a mock or a database on localhost. In production the call crosses DNS, a proxy, a firewall or a security group, and TLS with a certificate the JVM truststore may not trust. Connection refused, unknown host and handshake errors in the log show which one.
- Permissions. The production role, IAM policy, database user or file system is more restricted than my local admin access.
- Data and load. Production has real data volume, nulls, unusual characters, time zones and concurrency. A query that is instant on 100 local rows can time out on 50 million, and a connection pool sized for one developer runs out under real traffic.
- Resource limits. Container memory and CPU limits, read-only file systems, and request timeouts at the load balancer or gateway that do not exist locally.
Reproduce, fix and prevent. Once I have a suspect, I reproduce it in staging with production-like config or data, fix it, and then add a guard: validate required config at startup so the app fails fast, add a readiness check for the downstream, or pin the version. If users are affected while I investigate, I roll back first and debug after.
Alternate interview scenarios
"Errors start right after a deployment. What do you do?"
I treat the deployment as the main suspect and limit the damage first: if error rate or latency clearly rose after the rollout, I roll back or shift traffic back, then investigate. I compare what changed between the two versions: code, config, dependencies, database migrations and feature flags. Then I compare metrics and logs of old and new pods side by side. A backward-incompatible database migration is the dangerous case, because rolling back the code may not undo it; that is why schema changes should be expand-and-contract, so old and new versions both work during the rollout.
"How do you find the root cause from application logs?"
I start from the time the problem began and one failing request ID, not from a full-text search for "error". I filter by that correlation ID across services to rebuild the request's path, find the first error in time rather than the loudest one, and read its stack trace down to the root cause. Then I check whether the same error shows up for other requests and whether it started with a deploy, a config change or a traffic spike. Structured JSON logs with the request ID, user or tenant, and service version on every line make this a query instead of a hunt.
Sources (4)
- The Twelve-Factor App: Dev/prod parity12factor.net
- The Twelve-Factor App: Config12factor.net
- Spring Boot: Externalized configuration (property source order)docs.spring.io
- Spring Boot: Actuator endpoints (env, configprops)docs.spring.io