Top 10 Java, Microservices & Kubernetes Interview Questions Every Senior Tech Lead Should Know

Most interview questions test your memory. Great interview questions test your engineering judgment.

Over the years, I’ve interviewed hundreds of Java developers ranging from fresh graduates to Solution Architects. One thing has become increasingly clear: senior roles are no longer about syntax. They’re about understanding how Java applications behave in production, how microservices communicate, and how applications survive in Kubernetes.

In this article, we’ll cover 10 multiple-choice questions that reflect real-world enterprise scenarios. Each question is followed by the correct answer and a detailed explanation.


Question 1 – Java

A Spring Boot application is deployed in Kubernetes with the following configuration:

  • Container Memory = 2 GB
  • JVM Heap (-Xmx) = 1 GB

The Pod frequently reports OOMKilled, even though Heap usage never exceeds 60%.

What is the most likely reason?

A. Garbage Collection is not running frequently enough.

B. Kubernetes monitors only Heap usage.

C. Non-Heap memory exceeded the container memory limit.

D. Oracle Database consumed the Pod’s memory.

✅ Correct Answer

C. Non-Heap memory exceeded the container memory limit.

Explanation

Many developers mistakenly assume that -Xmx represents the JVM’s total memory usage. In reality, container memory includes:

  • Java Heap
  • Metaspace
  • Thread Stacks
  • Direct Buffers
  • Native Memory
  • JVM Internal Structures

Kubernetes monitors total container memory, not just Heap. If the combined memory exceeds the container limit, the Linux OOM Killer terminates the process and Kubernetes reports the Pod as OOMKilled.


Question 2 – Java

Which concurrency mechanism is best suited for calling three independent REST APIs simultaneously and combining their responses?

A. synchronized

B. CompletableFuture

C. AtomicInteger

D. ThreadLocal

✅ Correct Answer

B. CompletableFuture

Explanation

CompletableFuture is ideal for I/O-bound parallel processing, such as:

  • Calling multiple REST services
  • Database queries
  • Reading files
  • External API aggregation

Using it can significantly reduce response time by executing independent tasks concurrently. It should not be used indiscriminately for CPU-intensive work.


Question 3 – Java

Why is using ThreadLocal considered risky in Spring Boot applications running on Tomcat?

A. It reduces application performance.

B. It creates additional database connections.

C. Thread pool reuse can leak request data if values are not cleared.

D. It prevents Garbage Collection.

✅ Correct Answer

C. Thread pool reuse can leak request data if values are not cleared.

Explanation

Tomcat reuses worker threads across multiple requests. If a ThreadLocal variable is not removed after request completion, the next request handled by the same thread may inadvertently access stale data, leading to security and data consistency issues.


Question 4 – Microservices

Which pattern is most appropriate for maintaining data consistency across multiple microservices without using distributed transactions?

A. Singleton Pattern

B. Saga Pattern

C. Factory Pattern

D. Observer Pattern

✅ Correct Answer

B. Saga Pattern

Explanation

The Saga Pattern coordinates distributed transactions using a sequence of local transactions and compensation actions. Rather than locking multiple databases through XA transactions, each service commits its own work independently and compensates if a later step fails.

This approach improves scalability, resilience, and availability.


Question 5 – Microservices

A payment service must ensure that duplicate client requests never create duplicate payments.

Which approach is the most appropriate?

A. Synchronize the controller method.

B. Increase the database connection pool.

C. Implement an Idempotency Key.

D. Use a Singleton service.

✅ Correct Answer

C. Implement an Idempotency Key.

Explanation

Financial APIs should be idempotent. Each request carries a unique Idempotency Key, allowing the server to recognize retries and return the original response instead of processing the payment again.

This is a common pattern used by payment providers such as Stripe and PayPal.


Question 6 – Microservices

Why is “Database per Microservice” considered a best practice?

A. It reduces JVM memory usage.

B. It enforces service autonomy and prevents tight coupling.

C. It guarantees better SQL performance.

D. It eliminates the need for caching.

✅ Correct Answer

B. It enforces service autonomy and prevents tight coupling.

Explanation

Each microservice should own its data. Sharing the same database across services creates tight coupling, makes independent deployment difficult, and allows one service to bypass another’s business rules.

Independent data ownership is a fundamental principle of microservice architecture.


Question 7 – Kubernetes

Which Kubernetes probe determines whether traffic should be routed to a Pod?

A. Startup Probe

B. Readiness Probe

C. Liveness Probe

D. Node Probe

✅ Correct Answer

B. Readiness Probe

Explanation

The Readiness Probe indicates whether the application is capable of serving requests.

If it fails:

  • The Pod continues running.
  • Kubernetes removes it from the Service endpoints.
  • No new traffic is routed to it.

This allows applications to recover from temporary dependency failures without restarting.


Question 8 – Kubernetes

A Spring Boot application requires approximately 90 seconds to load caches, establish messaging connections, and initialize business rules.

Which probe is specifically designed for this scenario?

A. Startup Probe

B. Liveness Probe

C. Readiness Probe

D. Ingress Health Check

✅ Correct Answer

A. Startup Probe

Explanation

Startup Probes protect applications with long initialization times.

Without a Startup Probe, Kubernetes may interpret the slow startup as a failure and repeatedly restart the Pod, eventually resulting in a CrashLoopBackOff.


Question 9 – Kubernetes

What is the primary purpose of CPU Requests in Kubernetes?

A. To limit maximum CPU usage.

B. To reserve CPU resources during scheduling.

C. To restart Pods under heavy load.

D. To configure Horizontal Pod Autoscaling.

✅ Correct Answer

B. To reserve CPU resources during scheduling.

Explanation

CPU Requests represent the minimum CPU resources guaranteed to a Pod and are used by the Kubernetes Scheduler when selecting a node.

CPU Limits, on the other hand, cap the maximum CPU the Pod can consume. Exceeding the CPU limit results in throttling rather than termination.


Question 10 – Kubernetes

During a rolling deployment, Kubernetes sends a SIGTERM signal to the old Pod.

What should a well-designed Spring Boot application do after receiving this signal?

A. Immediately terminate the JVM.

B. Reject all requests and exit.

C. Finish in-flight requests, release resources, and shut down gracefully.

D. Ignore the signal until the deployment completes.

✅ Correct Answer

C. Finish in-flight requests, release resources, and shut down gracefully.

Explanation

A graceful shutdown prevents customer-facing errors during deployments.

A production-ready application should:

  • Stop accepting new requests.
  • Complete ongoing transactions.
  • Commit or roll back active database operations.
  • Close messaging consumers and producers.
  • Release resources cleanly before exiting.

This approach enables zero-downtime deployments and is an essential characteristic of cloud-native Spring Boot applications.


Final Thoughts

Senior Java interviews today extend well beyond Java syntax. Organizations expect candidates to understand how applications behave under production workloads, how distributed systems communicate, and how Kubernetes manages containerized applications.

If you can confidently explain why a Pod becomes OOMKilled, how a Saga Pattern maintains consistency, or when to use a Readiness Probe instead of a Liveness Probe, you’re demonstrating the kind of production knowledge expected from a Senior Developer or Tech Lead.

Coming Next

In the next article, we’ll cover 10 more enterprise interview questions focusing on:

  • Spring Boot Internals
  • Spring Security
  • Kafka & Event-Driven Architecture
  • Redis & Caching
  • System Design Scenarios
  • Production Troubleshooting

These questions are based on real interview discussions commonly used for Senior Java Developer, Tech Lead, and Solution Architect roles.

Leave a Reply

Your email address will not be published. Required fields are marked *