🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

माइक्रोसर्विसेज आर्किटेक्चर गाइड 2026: डिजाइन, संचार और लचीलापन

⏱️3 min read  ·  630 words

2026 में माइक्रोसर्विसेज आर्किटेक्चर काफी परिपक्व हो गया है। “माइक्रोसर्विसेज नर्क” के वर्षों के बाद जहां टीमों ने बहुत सारी छोटी-छोटी सेवाएं बनाईं, उद्योग ने ऐसे पैटर्न पर काम किया है जो परिचालन सादगी के साथ मॉड्यूलरिटी को संतुलित करते हैं। यह मार्गदर्शिका बताती है कि माइक्रोसर्विसेज का उपयोग कब करना है, उन्हें कैसे डिज़ाइन करना है और कठिन भागों को कैसे संभालना है।

मोनोलिथ बनाम माइक्रोसर्विसेज बनाम मॉड्यूलर मोनोलिथ

दृष्टिकोण कब उपयोग करें व्यापार नापसंद
एकाश्म स्टार्टअप, <10 इंजीनियर, अज्ञात डोमेन निर्माण/डीबग करना सरल, स्वतंत्र रूप से स्केल करना कठिन
मॉड्यूलर मोनोलिथ बढ़ती टीम, स्पष्ट सीमित संदर्भ, एकल तैनाती दोनों दुनियाओं में सर्वश्रेष्ठ – मॉड्यूलर लेकिन सरल
माइक्रोसर्विसेज बड़ा संगठन, स्वतंत्र टीम स्केलिंग, पॉलीग्लॉट तकनीक स्वतंत्र स्केलिंग/तैनाती, जटिल वितरित प्रणाली

2026 सर्वसम्मति: मॉड्यूलर मोनोलिथ से शुरुआत करें, जब आपके पास स्पष्ट कारण (पैमाना, स्वतंत्र तैनाती, टीम स्वायत्तता) हो तो सेवाएं निकालें।

बंधे हुए संदर्भ और सेवा डिज़ाइन

अच्छे माइक्रोसर्विसेज डोमेन-संचालित डिज़ाइन (डीडीडी) से जुड़े संदर्भों के साथ संरेखित होते हैं:

E-commerce domain bounded contexts:

Order Service (owns orders, order items)
  - Create order
  - Update order status
  - Get order history

Product Service (owns products, inventory)
  - List products
  - Update inventory
  - Product search

User Service (owns users, auth)
  - Register, login
  - Profile management
  - Authentication tokens

Payment Service (owns payment processing)
  - Process payment
  - Handle refunds
  - Payment status

Notification Service (owns notifications)
  - Email, SMS, push
  - Triggered by events from other services

Each service:
  - Has its own database (database-per-service pattern)
  - Is owned by one team
  - Can be deployed independently
  - Communicates via API or events (not shared DB)

संचार पैटर्न

सिंक्रोनस (आरईएसटी/जीआरपीसी)

# REST API call between services
import httpx
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10))
async def get_user(user_id: int) -> dict:
    async with httpx.AsyncClient(base_url="http://user-service:8001") as client:
        r = await client.get(f"/api/users/{user_id}", timeout=5.0)
        r.raise_for_status()
        return r.json()

# Use circuit breaker for resilience
from circuitbreaker import circuit

@circuit(failure_threshold=5, recovery_timeout=30)
async def call_payment_service(order_id: int, amount: float):
    async with httpx.AsyncClient(timeout=10) as client:
        return await client.post("http://payment-service/payments",
                                 json={"order_id": order_id, "amount": amount})

अतुल्यकालिक (काफ्का के साथ घटना-संचालित)

from aiokafka import AIOKafkaProducer, AIOKafkaConsumer
import json

# Produce event when order is created
async def publish_order_created(order: dict):
    producer = AIOKafkaProducer(bootstrap_servers="kafka:9092")
    await producer.start()
    try:
        event = {
            "event_type": "order.created",
            "order_id": order["id"],
            "user_id": order["user_id"],
            "total": order["total"],
            "timestamp": datetime.utcnow().isoformat()
        }
        await producer.send("orders", json.dumps(event).encode())
    finally:
        await producer.stop()

# Notification service consumes the event
async def consume_order_events():
    consumer = AIOKafkaConsumer(
        "orders",
        bootstrap_servers="kafka:9092",
        group_id="notification-service",
        auto_offset_reset="earliest"
    )
    await consumer.start()
    async for msg in consumer:
        event = json.loads(msg.value)
        if event["event_type"] == "order.created":
            await send_confirmation_email(event["user_id"], event["order_id"])

एपीआई गेटवे पैटर्न

# Kong / nginx / custom gateway routes
# All clients talk to one entry point:
# POST /api/orders -> Order Service :8001
# GET /api/products -> Product Service :8002
# POST /api/auth -> User Service :8003

# Kong route configuration
routes:
  - name: orders
    paths: ["/api/orders"]
    service: order-service
    plugins:
      - name: jwt           # validate JWT
      - name: rate-limiting # 100/min per user
      - name: request-transformer

  - name: products
    paths: ["/api/products"]
    service: product-service
    plugins:
      - name: response-ratelimiting

वितरित अनुरेखण

# OpenTelemetry — trace requests across services
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# Setup (once at startup)
provider = TracerProvider()
jaeger_exporter = JaegerExporter(agent_host_name="jaeger", agent_port=6831)
provider.add_span_processor(BatchSpanProcessor(jaeger_exporter))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer(__name__)

# Instrument FastAPI
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor

FastAPIInstrumentor.instrument_app(app)  # auto-instruments all routes
HTTPXClientInstrumentor().instrument()   # auto-instruments httpx calls

# Manual span for business logic
async def process_order(order_id: int):
    with tracer.start_as_current_span("process_order") as span:
        span.set_attribute("order.id", order_id)
        order = await get_order(order_id)
        span.set_attribute("order.total", order["total"])
        await charge_payment(order)
        await send_confirmation(order)

सेवा स्वास्थ्य और लचीलापन

from fastapi import FastAPI
from datetime import datetime

app = FastAPI()

@app.get("/health")
async def health():
    return {
        "status": "healthy",
        "timestamp": datetime.utcnow().isoformat(),
        "version": "1.2.3",
        "dependencies": {
            "database": await check_db(),
            "redis": await check_redis(),
        }
    }

@app.get("/ready")
async def readiness():
    # Check if service can handle traffic
    if not db_pool or not redis_client:
        raise HTTPException(503, "Service not ready")
    return {"status": "ready"}

# Kubernetes probes:
# livenessProbe: /health (if fails: restart container)
# readinessProbe: /ready (if fails: remove from load balancer)

माइक्रोसर्विसेज का उपयोग कब नहीं करना चाहिए

  • छोटी टीम (5 इंजीनियरों से कम)– परिचालन ओवरहेड वेग को ख़त्म कर देता है
  • प्रारंभिक उत्पाद– डोमेन सीमाएँ अभी तक स्पष्ट नहीं हैं
  • सरल CRUD ऐप– कोई स्केलिंग औचित्य नहीं
  • नेटवर्क विलंबता महत्वपूर्ण है– अंतर-सेवा कॉल विलंबता जोड़ती है
  • कोई DevOps परिपक्वता नहीं– पहले सीआई/सीडी, निगरानी, ​​ट्रेसिंग की जरूरत है

2026 में माइक्रोसर्विसेज तब सबसे अच्छा काम करते हैं जब: टीमें स्वतंत्र रूप से सेवाओं के मालिक होने के लिए पर्याप्त बड़ी हों, सीमित संदर्भ स्पष्ट हों, और आपके पास वितरित सिस्टम को संभालने के लिए DevOps बुनियादी ढांचा हो। एक अच्छी तरह से संरचित मॉड्यूलर मोनोलिथ से शुरुआत करें और सेवाएं तभी निकालें जब आप स्पष्ट दर्द बिंदुओं पर पहुंचें।

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা