1. What are microservices?
Microservices is an architectural style where an application is built as a collection of small, independent services that communicate over lightweight protocols like HTTP or messaging queues. Each service focuses on a specific business capability, ensuring loose coupling and high cohesion.
2. What are the key features of microservices architecture?
- Decentralized governance: Independent teams for development.
- Componentization: Each service is a component.
- Flexibility in technology: Services can use different tech stacks.
- Scalability: Services can scale independently.
- Resilience: Faults are isolated.
3. How do microservices communicate with each other?
Microservices communicate through:
- Synchronous communication: HTTP/REST APIs, gRPC.
- Asynchronous communication: Message brokers like RabbitMQ, Kafka, or JMS.
4. How do you handle service discovery in microservices?
Service discovery is implemented using tools like:
- Client-side discovery: Services register with a service registry (e.g., Eureka, Consul).
- Server-side discovery: Services register, and the API Gateway resolves requests using a registry.
5. What is the role of an API Gateway in microservices?
API Gateways handle:
- Routing requests to appropriate services.
- Load balancing.
- Authentication and authorization.
- Caching and monitoring.
Examples: Spring Cloud Gateway, Kong, NGINX.
6. How do you handle distributed transactions in microservices?
Using SAGA patterns, such as:
- Choreography: Events trigger local transactions.
- Orchestration: A central controller manages transaction states.
Tools like Camunda and Axon can help manage SAGA workflows.
7. What challenges arise in microservices testing?
- Service dependencies: Hard to isolate services.
- Data consistency: Distributed systems lead to eventual consistency.
- Integration testing: Requires mock services.
- Performance: Monitoring inter-service latency.
8. What is eventual consistency? How is it handled?
In distributed systems, eventual consistency means all data replicas will synchronize over time. It’s achieved through:
- Event-driven architecture: Using Kafka, RabbitMQ.
- CQRS: Separating command and query models.
9. How do you ensure fault tolerance in microservices?
- Retry mechanisms: Retry failed calls.
- Circuit breakers: Using libraries like Hystrix, Resilience4j.
- Fallbacks: Provide default responses.
- Bulkheads: Isolate resources for critical services.
10. How do you handle inter-service communication failure?
- Implement timeouts and retries.
- Use circuit breakers.
- Implement fallback mechanisms.
11. What is the role of Docker and Kubernetes in microservices?
- Docker: Containerizes microservices for consistency across environments.
- Kubernetes: Orchestrates and manages containers, ensuring scaling, high availability, and load balancing.
12. How do you ensure security in microservices?
- Authentication and authorization: Use OAuth 2.0 and JWT.
- API Gateway: Centralized security policies.
- Secure communication: Use HTTPS and mutual TLS.
- Secrets management: Use tools like Vault.
13. What are sidecars in microservices?
Sidecars are helper containers that run alongside main service containers to handle cross-cutting concerns like logging, monitoring, and security.
14. What is service mesh?
A service mesh (e.g., Istio, Linkerd) is a dedicated infrastructure layer that handles inter-service communication, security, and observability.
15. How do you monitor microservices?
- Tools: Prometheus, Grafana, ELK stack, Jaeger, Zipkin.
- Metrics: CPU, memory, request latency, error rates.
16. How do you deploy microservices?
- Containerized deployments: Docker + Kubernetes.
- CI/CD pipelines: Tools like Jenkins, GitHub Actions.
- Canary deployments: Gradual release to a subset of users.
- Blue-Green deployments: Parallel environments.
17. What is DDD (Domain-Driven Design) in microservices?
DDD emphasizes creating services around business domains with clearly defined boundaries, ensuring better modularity and separation.
18. How do you handle data sharing between microservices?
- Database per service: Services have their own databases.
- Event-driven communication: Use events to share updates.
- API queries: Services expose read-only APIs.
19. What are idempotent operations in microservices?
An idempotent operation produces the same result no matter how many times it’s executed (e.g., DELETE request in REST).
20. How do you manage configuration in microservices?
- Externalized configurations: Using tools like Spring Cloud Config or Consul.
- Environment-specific settings: Separate configurations per environment.
21. What is bounded context in microservices?
A bounded context is a DDD concept where each microservice owns a well-defined business area to avoid overlaps and dependencies.
22. How do you handle versioning in REST APIs?
- URI versioning:
/v1/resource. - Header versioning:
Accept: application/vnd.api.v1+json. - Query parameters:
?version=1.
23. What are anti-patterns in microservices?
- Shared database: Coupling between services.
- Over-engineering: Adding microservices unnecessarily.
- Too fine-grained services: Leads to performance issues.
24. What is the 12-factor app methodology?
Guidelines for building scalable and portable applications, covering aspects like configuration, logging, dependency management, and disposability.
25. What is a distributed log aggregator, and why is it used?
A distributed log aggregator collects logs from all microservices. Tools like the ELK stack and Fluentd are used for centralized logging and troubleshooting.


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.