🔧 Core Spring Boot Basics (Must-Know)
1. What is Spring Boot?
Answer: Spring Boot is a framework built on Spring that auto-configures default setups, embeds a
server (like Tomcat), and simplifies building production-ready applications with minimal
configuration.
2. How does Spring Boot help in microservices?
Answer: It accelerates development by reducing boilerplate, supports embedded servers, starter
dependencies, and provides production-ready features like Actuator for health and metrics.
🧠 Microservices Fundamentals
3. What are Microservices?
Answer: Microservices are small, independent services focused on a single business function,
deployed and scaled independently, communicating over lightweight protocols like REST or
messaging.
4. Monolith vs Microservices
Answer: Monolith is a single deployable unit. Microservices split business logic into modular services
— improving scalability, deployment speed, and team autonomy but increasing distributed
complexity.
5. What is Spring Cloud?
Answer: Extension of Spring Boot providing tools for distributed systems: service discovery, config
server, load balancing, circuit breakers, etc.
Service Discovery & Communication
6. What is Service Discovery? Why needed?
Answer: Services register themselves (e.g., Eureka) and discover peers dynamically instead of
hardcoded IPs — helpful in dynamic environments where instances scale up/down.
7. How do microservices communicate?
Answer:
Synchronous: REST APIs
Asynchronous: Messaging systems like Kafka/RabbitMQ for decoupled workflows.
8. What is OpenFeign?
Answer: Declarative REST client that simplifies inter-service calls using annotated Java interfaces.
🚀 Resilience, Load Balancing & Config
9. What is Load Balancing?
Answer: Distributes requests across multiple instances. In Spring Cloud, it can be done via Spring
Cloud LoadBalancer or Ribbon (older).
10. What is a Circuit Breaker?
Answer: A pattern (often via Resilience4j) to stop calling a failing service, preventing cascading
failures, and providing fallback behavior.
11. Explain centralized config
Answer: Spring Cloud Config Server holds external configs (often Git-backed) and serves them to all
services — no need to hardcode settings in each.
🔄 Advanced but Useful Concepts
12. What is the Saga Pattern?
Answer: Manages distributed transactions across services. Each service does a local transaction and
emits events. If a step fails, compensating actions undo prior work.
13. What is API Gateway?
Answer: Single entry point (e.g., Spring Cloud Gateway) routing requests, handling auth, rate
limiting, logging — without business logic.
14. What is distributed tracing and why important?
Answer: Tracks a request across services (Zipkin/Jaeger). It helps identify where latency or failure
happens end-to-end.
🧪 Testing & Deployment
15. How do you test microservices?
Answer:
Unit tests (JUnit/Mockito)
Integration tests (@SpringBootTest)
Contract tests
E2E tests.
16. How to deploy microservices?
Answer: Containerize using Docker, orchestrate (e.g., Kubernetes), and use CI/CD pipelines.
📌 Scenario-Based Questions (Great for 2YOE)
17. A dependent service is slow → what do you do?
Answer: Add timeouts, retries, circuit breaker/fallbacks, use tracing to pinpoint the slow component.
18. Traffic spike hits your API → how to mitigate?
Answer: API Gateway rate limiting, horizontal scaling of service instances, better load balancing.
19. How do you handle config changes without redeploying?
Answer: Use Spring Cloud Config Server and refresh endpoints or Spring Cloud Bus.
20. One service dies — how to avoid total outage?
Answer: Circuit breakers, fallback responses, service retry policies, and graceful degradation.
👌 Tips for 2 Years Experience Interviews
✔ Be ready to explain code you wrote and design decisions.
✔ Focus on scenario-based answers, not just definitions.
✔ Show familiarity with Actuator, Resilience4j, Feign, Gateway, Config Server.
✔ Understand why a pattern/design choice was made in your project.
If you want, I can also give mock interview practice questions with model answers that you can
rehearse — just let me know! 👨💻
yes please
Great 👍 Since you have experience in Spring Boot + Microservices, here is a realistic mock interview
round designed for 2 years experience.
I’ll structure this like an actual technical interview:
🔹 Question
✅ What interviewer expects
💬 Sample strong answer (you can practice speaking this)
🧑💻 MOCK INTERVIEW – Spring Boot + Microservices (2 YOE)
🔹 1. Explain your current project architecture.
✅ What interviewer checks:
Do you understand system design?
Can you explain service interaction clearly?
💬 Sample Answer:
In my current project, we follow microservices architecture. Each service handles a specific business
domain like User Service, Order Service, and Payment Service.
We use Spring Boot for service development.
Services communicate via REST APIs using OpenFeign.
We use Eureka for service discovery and Spring Cloud Gateway as an API Gateway.
Configuration is managed using Spring Cloud Config Server.
For database, each service has its own database to maintain loose coupling.
We use MySQL and Hibernate (JPA) for ORM.
For fault tolerance, we implemented Resilience4j circuit breaker.
🔹 2. What happens internally when you start a Spring Boot application?
✅ Expected:
Understanding of auto-configuration and embedded server.
💬 Sample Answer:
When we start a Spring Boot application, the main method calls [Link]().
It creates the ApplicationContext, performs component scanning, loads auto-configuration classes
using @EnableAutoConfiguration, and starts the embedded Tomcat server.
Then it initializes all beans and the application becomes ready to serve requests.
🔹 3. How do microservices communicate in your project?
💬 Sample Answer:
We use synchronous communication via REST using OpenFeign.
For some asynchronous operations like notifications, we use Kafka to avoid blocking calls and
improve performance.
🔹 4. What is Circuit Breaker? Have you used it?
💬 Sample Answer:
Yes, we use Resilience4j as circuit breaker.
It prevents cascading failures.
If a dependent service fails continuously, the circuit opens and fallback logic executes instead of
repeatedly calling the failing service.
This improves system stability.
🔹 5. How do you handle distributed transactions?
💬 Sample Answer:
Since microservices have separate databases, we avoid traditional ACID transactions.
We use the Saga pattern.
Each service performs a local transaction and publishes events.
If any step fails, compensating transactions are executed to maintain consistency.
🔹 6. Difference between @Component, @Service, @Repository
💬 Sample Answer:
All are stereotype annotations.
@Component is generic.
@Service is used for business logic layer.
@Repository is used for DAO layer and provides exception translation mechanism.
🔹 7. How do you improve performance of a slow API?
💬 Sample Answer:
First, I analyze logs and enable tracing.
Then I check database query performance.
If needed, I add caching (Redis).
I also optimize queries and add pagination.
If load is high, we scale the service horizontally.
🔹 8. What is the difference between Monolithic and Microservices?
💬 Sample Answer:
Monolithic architecture has a single deployable unit.
Microservices break application into smaller independent services.
Microservices improve scalability and deployment flexibility but increase operational complexity.
🔹 9. What is Actuator?
💬 Sample Answer:
Spring Boot Actuator provides production-ready features like health check, metrics, environment
properties, and monitoring endpoints.
We use /actuator/health for checking service status.
🔹 10. Have you faced any production issue? Explain.
👉 This is very important for 2 YOE.
💬 Sample Answer:
Yes, once we had high response time in Order Service.
After analysis, we found a missing database index.
We added indexing and optimized the query.
Response time reduced significantly.
This taught me importance of DB optimization.
🔥 Advanced Questions (Sometimes Asked)
What is @Transactional propagation?
Difference between RestTemplate and WebClient?
How does Spring Security work?
What is JWT?
What is API Gateway?
What is Idempotency?
What is Docker? Why needed for microservices?
🎯 Interview Tip for YOU (Important)
Since you have ~2 years experience, interviewers will focus on:
Real project explanation
Debugging skills
Understanding of REST, DB, exceptions
Basic cloud/container knowledge
Not deep system design
They expect practical understanding, not senior-level architecture.
If you want, I can now:
1️⃣ Take a live mock interview (I ask, you answer, I correct you)
2️⃣ Give advanced scenario-based questions
3️⃣ Provide Spring Boot coding interview questions
4️⃣ Give Java core tricky questions
Tell me which one you want 👨💻
What is @Transactional propagation? Difference between RestTemplate and WebClient? How does
Spring Security work? What is JWT? What is API Gateway? What is Idempotency? What is Docker?
Why needed for microservices
Perfect 👍 These are very common 2–3 years experience interview questions in Spring Boot +
Microservices.
I’ll give you interview-ready answers (clear + crisp + practical).
🔹 1. What is @Transactional Propagation?
@Transactional propagation defines how a transaction behaves when one transactional method
calls another transactional method.
🔑 Common Propagation Types:
✅ REQUIRED (Default)
Joins existing transaction.
If no transaction exists, creates a new one.
💬 Interview Answer:
REQUIRED will use the current transaction if available; otherwise it creates a new one.
✅ REQUIRES_NEW
Always creates a new transaction.
Suspends existing transaction.
💬 Example Use Case:
Logging or audit table insertion even if main transaction fails.
✅ SUPPORTS
Runs inside transaction if exists.
Otherwise runs without transaction.
✅ NOT_SUPPORTED
Always runs without transaction.
✅ MANDATORY
Must run inside an existing transaction.
Throws exception if none exists.
🎯 Interview Tip:
Most commonly used: REQUIRED and REQUIRES_NEW.
🔹 2. Difference Between RestTemplate and WebClient
Feature RestTemplate WebClient
Type Blocking Non-blocking
Introduced In Older Spring Spring WebFlux
Performance Thread per request Event loop model
Feature RestTemplate WebClient
Reactive Support ❌ No ✅ Yes
💬 Interview Answer:
RestTemplate is synchronous and blocks the calling thread.
WebClient is asynchronous and non-blocking, introduced with Spring WebFlux.
WebClient is preferred in modern microservices for better scalability.
⚠️Note: RestTemplate is now in maintenance mode.
🔹 3. How Does Spring Security Work?
Spring Security works using filters.
Flow:
1. Request comes in.
2. Security filter chain intercepts request.
3. Authentication is checked.
4. If valid → Authorization rules applied.
5. If authorized → Request proceeds.
Main Components:
AuthenticationManager
UserDetailsService
PasswordEncoder
SecurityFilterChain
💬 Interview Answer:
Spring Security intercepts incoming requests using a filter chain.
It authenticates the user, checks authorization rules, and then allows or denies access to resources.
🔹 4. What is JWT?
JWT (JSON Web Token) is a token-based authentication mechanism.
It has 3 parts:
[Link]
Header → Algorithm & token type
Payload → User data (claims)
Signature → Security validation
💬 Interview Answer:
JWT is a stateless authentication mechanism.
After login, server generates a token and client sends it in Authorization header for every request.
Server validates the token instead of storing session data.
🔑 Used widely in microservices for stateless authentication.
🔹 5. What is API Gateway?
API Gateway acts as a single entry point for all client requests.
Common tool:
Spring Cloud Gateway
Responsibilities:
Routing
Authentication
Rate limiting
Logging
Load balancing
💬 Interview Answer:
API Gateway sits between client and microservices.
It routes requests to appropriate services and handles cross-cutting concerns like security and
logging.
🔹 6. What is Idempotency?
An operation is idempotent if multiple identical requests produce the same result.
Example:
GET → Idempotent
PUT → Idempotent
DELETE → Idempotent
POST → Usually NOT idempotent
💬 Interview Answer:
Idempotency ensures that repeated execution of the same request does not change the outcome
after the first execution.
It is important in microservices to prevent duplicate processing.
Example:
Payment API should not deduct money twice if request retries.
🔹 7. What is Docker? Why Needed for Microservices?
🔹 Docker is a containerization platform.
It packages:
Application
Dependencies
Runtime
Configuration
Into a container.
Why Needed in Microservices?
✔ Ensures consistency across environments
✔ Lightweight compared to VMs
✔ Easy deployment
✔ Works well with Kubernetes
✔ Helps scale services independently
💬 Interview Answer:
Docker allows us to package our Spring Boot microservice along with dependencies into a container.
It ensures the application runs the same in development, testing, and production environments.