Java Production-Related Interview Questions and Answers
1. What are common production issues in Java applications?
- Memory Leaks
- High CPU Usage
- OutOfMemoryError
- Thread Deadlocks
- Slow Response Times
- Service Failures
- Logging issues
- Configuration Errors
2. How do you debug high memory usage in production?
- Use tools: JVisualVM, jmap, jhat, MAT
- Analyze heap dumps
- Check for memory leaks in collections
- Tune JVM with -Xmx, -Xms
3. How do you handle and investigate high CPU usage?
- Use top, htop, jstack
- Match thread IDs with stack trace
- Find infinite loops or expensive operations
- Use profilers like VisualVM or Flight Recorder
4. How do you handle a microservice crash in production?
1. Check logs
2. Validate dependencies
3. Analyze resource usage
4. Restart and monitor
5. Perform RCA
5. How do you handle thread deadlocks?
- Use jstack or VisualVM
- Identify circular locking
- Reorder locks or use tryLock
- Redesign shared resource handling
6. How do you monitor a Java application in production?
- Prometheus + Grafana
- ELK Stack, Datadog, New Relic
- Monitor CPU, memory, GC, threads, API latency
7. What are some common exception types in production?
- NullPointerException, SQLException, TimeoutException, IOException
- Use proper logging, retry, fallback, circuit breaker patterns
8. How do you prevent memory leaks?
- Use try-with-resources
- Avoid static references to large objects
- Clean up caches
- Monitor heap usage
9. What are good logging practices?
- Use SLF4J with Logback/Log4j
- Proper log levels
- Centralized logging (ELK, Splunk)
- Add correlation IDs
10. How do you ensure zero-downtime deployments?
- Blue-green or canary deployments
- Use load balancers and feature flags
- Maintain backward compatibility
- Automate health checks
11. What are GC issues and how do you analyze them?
- Long GC pauses, OutOfMemoryError
- Use jstat, GC logs, GCeasy
- Tune with G1GC/ZGC, manage heap sizes
12. How do you handle failures in a distributed system?
- Retry with backoff
- Circuit breakers and bulkheads
- Timeout and fallback
- Use service mesh for observability
Spring Boot, Microservices, and Kafka Interview Q&A
13. What are common Spring Boot production issues?
- Port conflicts
- Misconfigured [Link]/yml
- Bean creation failures
- Memory leaks due to @Scheduled or caching
- Security misconfigurations
14. How do you monitor Spring Boot apps?
- Use Actuator endpoints
- Expose metrics via Micrometer
- Integrate with Prometheus/Grafana
- Use health checks (/actuator/health)
15. What are common microservices issues in production?
- Service discovery failures
- Network latency
- Broken APIs
- Inconsistent data
- Dependency failure propagation
16. How do you handle service-to-service communication failures?
- Use Resilience4j or Hystrix for circuit breakers
- Retry with exponential backoff
- Timeouts and fallback logic
- Logging and alerting
17. How do you secure communication between microservices?
- Use HTTPS and TLS
- OAuth2/JWT for authentication
- API gateways for request validation
- Mutual TLS (mTLS) where needed
18. What are common Kafka issues in production?
- Message loss due to incorrect offset handling
- Consumer lag
- Broker outages
- Incorrect partitioning
- Schema evolution failures
19. How do you monitor Kafka consumers?
- Monitor consumer lag using Kafka Manager or Burrow
- Track commit offsets
- Use JMX metrics
- Alert on lag or errors
20. How do you ensure idempotency in Kafka consumers?
- Use unique keys or transaction IDs
- Check DB before processing
- Deduplication logic in consumers
21. How do you handle schema evolution in Kafka?
- Use Schema Registry
- Follow backward/forward compatibility
- Version schemas carefully
- Avoid breaking changes
22. How do you handle scaling issues in Spring Boot microservices?
- Horizontal scaling with Kubernetes
- Use HikariCP for efficient DB connection pooling
- Optimize thread pool sizes
- Profile APIs and DB queries