0% found this document useful (0 votes)
3 views

Microservice_Architecture_Interview_Problems

The document outlines best practices for designing communication between microservices, emphasizing asynchronous communication and patterns like REST/HTTP and Kafka. It discusses handling distributed transactions with a focus on eventual consistency and the SAGA pattern, while also highlighting service discovery and load balancing strategies. Additionally, it covers design principles for minimizing coupling and maximizing cohesion, as well as ensuring observability and traceability through centralized logging and distributed tracing.

Uploaded by

pbecic
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Microservice_Architecture_Interview_Problems

The document outlines best practices for designing communication between microservices, emphasizing asynchronous communication and patterns like REST/HTTP and Kafka. It discusses handling distributed transactions with a focus on eventual consistency and the SAGA pattern, while also highlighting service discovery and load balancing strategies. Additionally, it covers design principles for minimizing coupling and maximizing cohesion, as well as ensuring observability and traceability through centralized logging and distributed tracing.

Uploaded by

pbecic
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Microservice Architecture

How would you design communication between microservices in a large-scale


system?
 Use asynchronous communication for loosely coupled services and synchronous
communication only when necessary.
 Patterns to consider:
 Synchronous: REST/HTTP, gRPC — suitable for real-time queries or tightly bound
services.
 Asynchronous: Kafka, RabbitMQ — ideal for event-driven workflows and decoupling.
 Best practices:
 Avoid chaining too many synchronous calls to reduce latency and cascading failures.
 Use correlation IDs and tracing for observability (e.g., OpenTelemetry).
 Apply backpressure, retries, and circuit breakers to manage failures.

How do you handle distributed transactions and maintain data consistency


across services?
 Avoid distributed ACID transactions when possible — they are complex and hard to
scale.
 Patterns for consistency:
 Eventual consistency using event-driven architecture.
 SAGA pattern: orchestrate or choreograph a sequence of local transactions with
compensation logic.
 Techniques:
 Use outbox pattern to reliably publish events after local DB commit.
 Ensure idempotency of handlers to safely reprocess events.
 Use unique identifiers and versioning for optimistic concurrency control.
 Monitoring and traceability are critical to detect and recover from partial failures.

What strategies would you use for service discovery and load balancing?
 Service discovery enables services to find each other dynamically.
 Options:
 Client-side discovery: service queries a registry (e.g., Eureka, Consul) and decides which
instance to call.
 Server-side discovery: API gateway or service mesh routes requests (e.g., NGINX, Istio).
 Load balancing strategies:
 Round-robin, least connections, or custom rules.
 Use health checks and circuit breakers to avoid failed instances.
 In Kubernetes:
 Leverage built-in DNS-based discovery and kube-proxy/IPTables for load balancing.
How do you design microservices to minimize coupling and maximize cohesion?
 Cohesion refers to how focused a service is on a single domain responsibility.
 Loose coupling ensures services can evolve independently.
 Design principles:
 Align service boundaries with bounded contexts from Domain-Driven Design (DDD).
 Encapsulate data within the service and expose operations via clear APIs.
 Use asynchronous messaging to reduce temporal coupling.
 Best practices:
 Avoid shared databases or direct access between services.
 Favor contracts and versioned APIs for stable communication.
 Treat each service as independently deployable and replaceable.

How would you ensure observability and traceability in a microservices


architecture?
 Observability allows you to understand internal state based on external outputs like
logs, metrics, and traces.
 Key practices:
 Centralized logging using ELK, Loki, or similar tools.
 Distributed tracing using OpenTelemetry, Jaeger, or Zipkin.
 Expose Prometheus-compatible metrics from each service.
 Use correlation IDs:
 Pass a unique request ID across services to correlate logs and traces.
 Define SLOs and error budgets to drive operational improvements.

You might also like