Spring Boot
Spring Boot Interview Questions & Answers (50+)
By Utility Zone ยท 2026-01-28T12:20:11.156242
Mapped to Expense Tracker Capstone Project
This document contains 50+ detailed Spring Boot interview questions and answers, all mapped to the Expense Tracker backend you built.
1. Spring Boot Fundamentals
Q1. What problem does Spring Boot solve?
Spring Boot eliminates boilerplate configuration by providing auto-configuration, embedded servers, and starter dependencies.
In my Expense Tracker project, it enabled rapid setup of REST APIs, JPA, Security, caching, and monitoring.
Q2. What is auto-configuration?
Auto-configuration configures beans automatically based on classpath dependencies.
For example, adding Spring Data JPA auto-configured Hibernate and datasource.
Q3. What are Spring Boot starters?
Starters are curated dependency bundles.
Example: spring-boot-starter-web provides Spring MVC, Jackson, and embedded Tomcat.
Q4. Difference between Spring and Spring Boot?
Spring requires manual configuration, while Spring Boot provides opinionated defaults and faster development.
Q5. What is embedded Tomcat?
Embedded Tomcat allows applications to run as standalone JARs without external servers.
2. REST API Design
Q6. How did you design REST APIs?
Using proper HTTP methods, resource-based URLs, DTOs, and meaningful status codes.
Q7. Why use DTOs?
DTOs prevent exposing entities and sensitive data such as passwords.
Q8. How do you handle pagination?
Using Spring Data Pageable to return paginated expense data.
Q9. What status codes do you commonly use?
200, 201, 400, 401, 403, 404 based on request outcome.
Q10. How do you ensure API consistency?
By centralizing validation and exception handling.
3. Spring Data JPA
Q11. Why Spring Data JPA?
It reduces boilerplate and simplifies database access.
Q12. What is JpaRepository?
An interface providing CRUD, pagination, and sorting support.
Q13. How did you model relationships?
Using @ManyToOne between Expense and User.
Q14. What is lazy loading?
Fetching related entities only when needed to improve performance.
Q15. How did you optimize DB performance?
Pagination, indexing, and JPQL aggregation queries.
4. Security
Q16. How does JWT authentication work?
Login โ Validate credentials โ Generate JWT โ Validate token on every request.
Q17. Why JWT over sessions?
JWT is stateless and scalable for REST APIs.
Q18. Where is JWT stored?
On the client side and sent via Authorization header.
Q19. Authentication vs Authorization?
Authentication verifies identity; authorization controls access.
Q20. How did you enforce user data ownership?
User identity is extracted from JWT, never from request parameters.
5. Validation & Exception Handling
Q21. How did you validate inputs?
Using Bean Validation annotations like @NotBlank and @Email.
Q22. How are validation errors handled?
Spring automatically returns HTTP 400 with error details.
Q23. How did you implement global exception handling?
Using @RestControllerAdvice.
Q24. Why avoid try-catch in controllers?
Global handlers keep controllers clean.
Q25. What are custom exceptions?
Domain-specific exceptions like UserNotFoundException.
6. Caching & Performance
Q26. Why introduce caching?
To improve performance of read-heavy reporting APIs.
Q27. Which caching mechanism did you use?
Spring Cache abstraction with in-memory cache.
Q28. How do you prevent cache leaks?
Include user identity in cache keys.
Q29. When do you evict cache?
When expenses are created or updated.
Q30. Difference between @Cacheable and @CacheEvict?
@Cacheable stores results; @CacheEvict clears cache.
7. Logging & Monitoring
Q31. Which logging framework did you use?
SLF4J with Logback.
Q32. What log levels are used?
INFO, DEBUG, and ERROR.
Q33. Why is logging important?
For debugging and monitoring production issues.
Q34. What is Spring Boot Actuator?
Provides production-ready monitoring endpoints.
Q35. Which Actuator endpoints did you use?
/actuator/health and /actuator/metrics.
8. Docker & Deployment
Q36. Why Docker?
Ensures consistent environments across deployments.
Q37. How did you Dockerize the app?
Using a Dockerfile with Java 17 base image.
Q38. How do you externalize configuration?
Using environment variables.
Q39. Common deployment issues?
Missing env vars, port mismatch, memory limits.
Q40. How do you check app health?
Using /actuator/health.
9. Best Practices
Q41. How do you ensure clean architecture?
By separating concerns across layers.
Q42. Why avoid exposing entities?
To keep APIs stable and secure.
Q43. How do you handle sensitive data?
Never log or return sensitive fields.
Q44. How would you test this application?
Using unit and integration tests.
Q45. How does stateless architecture help?
It enables easy horizontal scaling.
10. System Design & Scaling
Q46. How would you scale this application?
Use PostgreSQL, Redis, and load balancers.
Q47. How would you handle high traffic?
Horizontal scaling and caching.
Q48. How would you secure production secrets?
Using environment variables or secret managers.
Q49. Why is this project interview-ready?
It demonstrates end-to-end backend skills.
Q50. How should you answer Spring Boot interview questions?
By explaining real implementations from your project.
--- END ---