Part 4 · Reliability ও Security 📖 ১১ মিনিট পড়া 📝 ২০টি কুইজ

Service Discovery

Microservice-গুলো একে অপরকে কীভাবে খুঁজে পায়?

📝 কুইজে যান

আপনার backend-এ ১০টি instance of Order Service চলছে। Auto-scaling-এ সংখ্যা বদলায় — ৫ থেকে ২০। প্রতিটির আলাদা IP। User Service "Order Service" call করতে চায় — কোন IP-তে call করবে? এই dynamic problem-এর solution = Service Discovery

Problem: Static Configuration ভাঙে

Traditional approach:

  • Config file-এ "Order service IP: 10.0.0.5"।
  • IP change হলে — config update + redeploy।
  • Auto-scaling = constant change।
  • Failed instance — request going there।

Service Discovery কী?

Service Discovery = একটি system যা track করে কোন service-এর কয়টি instance চলছে এবং প্রতিটির network location। Client এই service-কে query করে — current available instance পায়।

মূল components

  • Service Registry: Database of all running services + locations।
  • Service Provider: Service register itself।
  • Service Consumer: Registry query করে location পায়।
  • Health Check: Periodic check — alive কিনা।

Service Registration

Self-Registration

Service নিজেই startup-এ registry-তে register; shutdown-এ unregister; periodic heartbeat।

Third-party Registration

External agent (orchestrator) register/unregister করে। Kubernetes-এ kubelet automatic।

Discovery Patterns

Client-Side Discovery

Client registry query → instance list → load balance + call।

[Client] ↓ query [Service Registry] ↓ instance list [Client] choose + call → [Instance]
  • সুবিধা: Smart routing client-এ।
  • অসুবিধা: Client logic বেশি; multi-language complex।
  • Tools: Netflix Eureka + Ribbon।

Server-Side Discovery

Client load balancer-কে call → LB registry query করে instance pick + forward।

[Client] → [Load Balancer] ↓ query [Service Registry] ↓ [Instance]
  • সুবিধা: Client simple।
  • অসুবিধা: Extra hop (LB)।
  • Tools: AWS ELB, Kubernetes Service।
  • Consul: HashiCorp — full-featured, DNS-based discovery।
  • etcd: Kubernetes-এর backbone — distributed KV store।
  • ZooKeeper: Apache, Hadoop ecosystem।
  • Eureka (Netflix): AP-system, client-side discovery।
  • Kubernetes DNS: Built-in — Service-এ ClusterIP।
  • AWS Cloud Map: Managed service discovery।

DNS-Based Discovery

Service registration → DNS records। Client DNS lookup করে IP।

  • Standard, simple।
  • TTL caching issue।
  • SRV records advanced (port info)।
  • Kubernetes-এ default।

Kubernetes Service Discovery

K8s-এ service discovery built-in:

  • Pod created → automatically registered।
  • Service object — stable name (e.g., user-service)।
  • kube-dns বা CoreDNS — DNS-based resolve।
  • ClusterIP virtual — pod-এ load balance।
  • Pod fail = automatically removed।

Health Check

Service alive কিনা detect:

  • Heartbeat: Service periodically registry-তে ping।
  • HTTP health endpoint: /health 200 return।
  • TCP check: Port open কিনা।
  • Custom script: Application-specific।

Failure detect → instance unregister।

Service Mesh — Modern Approach

Istio, Linkerd, Consul Connect — sidecar proxy:

  • Service-to-service communication automate।
  • Discovery + load balance + retry + circuit breaker সব।
  • Application code-এ network logic নয়।
  • Per-service Envoy proxy।

বাস্তব উদাহরণ

  • Netflix: Eureka — pioneer।
  • Airbnb: SmartStack (Consul-based)।
  • Modern startup: Kubernetes built-in।
  • HashiCorp ecosystem: Consul।

Challenges

  • Eventual consistency: Registry update lag।
  • Stale entries: Crashed instance still listed।
  • Network partition: Registry unreachable = panic।
  • Registry HA: Itself shouldn't be SPOF।

সাধারণ ভুল ধারণা

  1. "DNS sufficient": Caching issue + no health check।
  2. "Manual config OK at small scale": Auto-scaling-এ ভাঙে।
  3. "Client-side > server-side": Use case-অনুযায়ী।

Best Practices

  • Health check mandatory।
  • Registry HA cluster (3-5 nodes)।
  • Short TTL — quick failure detect।
  • Service mesh-এ migrate consider — modern systems।
  • K8s থাকলে — built-in use।
  • Local cache + fallback if registry down।

📌 চ্যাপ্টার সারমর্ম

  • Service Discovery = dynamic location track।
  • Service Registry + provider + consumer + health check।
  • Client-side vs Server-side discovery patterns।
  • Consul, etcd, Eureka, K8s DNS — popular।
  • Service Mesh (Istio) — modern unified solution।