Backend7 min read

Microservices Architect

Designs microservice architectures - service boundaries, decomposition patterns, inter-service communication, distributed tracing, and when a monolith is the right answer.

microservicesservice meshservice boundariesdistributed systemsdecomposition

The Microservices Architect defines service boundaries and inter-service communication patterns. The most common mistake is decomposing too early - microservices add real operational complexity that a small team or young product cannot yet justify. This agent starts by questioning whether microservices are the right choice before designing them.

When to Use Microservices

SignalMonolithMicroservices
Team size< 10 engineersMultiple autonomous teams
Codebase ageEarly / undefined domainStable domain with clear boundaries
Deployment frequencyWeekly or lessMultiple deploys per day per service
Scale requirementsSingle region, low trafficServices with very different scale profiles
Tech diversitySingle language is fineServices genuinely need different tech stacks

Service Boundary Design (Domain-Driven)

// Bounded contexts define service boundaries
// Each service owns its data - never share a database

Services:
  ┌─────────────┐  ┌──────────────┐  ┌──────────────┐
  │  User Service│  │ Order Service │  │ Catalog Svc  │
  │  (Identity) │  │ (Commerce)   │  │ (Products)   │
  │  users DB   │  │  orders DB   │  │ products DB  │
  └─────────────┘  └──────────────┘  └──────────────┘

// Rule: a transaction that spans service boundaries is a warning sign
// If you need atomic transactions across services, consider merging them

// Service contract:
// - Expose a versioned API (REST or gRPC)
// - Publish domain events to message bus for async consumers
// - Never query another service's database directly

Inter-Service Communication

// Synchronous - request/response (use for reads that need immediate answer)
// Call User Service from Order Service:
const user = await fetch(`${process.env.USER_SERVICE_URL}/users/${userId}`, {
  headers: { 'x-service-key': process.env.USER_SERVICE_KEY },
  signal: AbortSignal.timeout(3000), // Always set a timeout
}).then(r => r.json());

// Async - events (use for writes that don't need immediate response)
// Order Service publishes event; downstream services consume:
await kafka.producer.send({
  topic: 'order.created',
  messages: [{ value: JSON.stringify({ orderId, userId, items, total }) }],
});

Distributed Tracing

// OpenTelemetry - instrument all services
import { trace, propagation } from '@opentelemetry/api';
import { NodeSDK } from '@opentelemetry/sdk-node';

const sdk = new NodeSDK({ serviceName: 'order-service' });
sdk.start();

// Propagate trace context in outbound HTTP calls
const tracer = trace.getTracer('order-service');
const span = tracer.startSpan('create-order');

// context.with injects trace headers into downstream calls
const headers = {};
propagation.inject(trace.setSpan(context.active(), span), headers);
// → X-Trace-ID and X-Span-ID headers added automatically

Explore all agents

Browse the full library of specialized AI agents.