Microservices & System Design Interview Questions (Java Backend)

What are Microservices?

Answer:

Microservices is an architectural style where an application is divided into small, independent services. Each service is responsible for a specific business functionality and can be developed, deployed, and scaled independently.


Monolith vs Microservices

Monolithic Architecture:

  • Single large application
  • All modules tightly coupled
  • Hard to scale

Microservices Architecture:

  • Multiple small services
  • Loosely coupled
  • Easy to scale and maintain

Advantages of Microservices

Answer:

  • Independent deployment
  • Better scalability
  • Fault isolation
  • Technology flexibility

What is API Gateway?

Answer:

API Gateway acts as a single entry point for all client requests and routes them to appropriate microservices.

Responsibilities:

  • Routing
  • Authentication
  • Load balancing

What is Service Discovery?

Answer:

Service Discovery helps services find each other dynamically without hardcoding URLs.

Example:

When one service wants to call another, it asks the discovery server for the service location.


What is Eureka Server?

Answer:

Eureka Server is a service registry used for service discovery in Spring Cloud.


What is Feign Client?

Answer:

Feign Client is used for communication between microservices. It simplifies REST API calls.

Example:

“`java id=”m1″
@FeignClient(name = “user-service”)
public interface UserClient {

@GetMapping("/users")
List<String> getUsers();

}
“`


What is Load Balancing?

Answer:

Load balancing distributes incoming requests across multiple servers to improve performance and reliability.


What is Circuit Breaker?

Answer:

Circuit Breaker prevents system failure by stopping calls to a failing service and providing fallback responses.


What is Config Server?

Answer:

Config Server is used to manage configuration centrally for all microservices.


System Design Basics


How to Design a System (Interview Approach)

Step-by-Step:

  1. Understand requirements
  2. Identify components
  3. Design APIs
  4. Database design
  5. Scaling strategy
  6. Security

Example: Design a URL Shortener (like Bitly)

Basic Flow:

  1. User enters long URL
  2. System generates short URL
  3. Store mapping in database
  4. Redirect to original URL when accessed

Components:

  • API Service
  • Database
  • Cache (Redis)
  • Load Balancer

Scaling in System Design

Techniques:

  • Horizontal scaling
  • Caching
  • Load balancing
  • Database sharding

What is CAP Theorem?

Answer:

CAP theorem states that a distributed system can only achieve two out of three:

  • Consistency
  • Availability
  • Partition Tolerance

Leave a Comment