Microservices architecture decomposes systems along business capabilities into autonomous Bounded Contexts. A non-negotiable rule is Database-per-Service: each microservice owns its private database. No other service may query its tables directly—all access must cross strict public API/gRPC or asynchronous event interfaces.
Independent sovereign countries: each country maintains its own internal currency and legal records. If Country A wants data from Country B, it sends a formal diplomatic ambassador (API request) rather than breaking into Country B’s confidential filing cabinets.
Change Data Capture (CDC via Debezium) streams internal database mutations directly into Kafka topics without dual-write race conditions.
Decomposition & Service Boundaries • starter
// Order Service - Autonomous Bounded Context with Private Database
import { Router } from 'express';
import { orderRepository } from './db/orderRepo';
import { eventBus } from './events/kafkaProducer';
export const orderRouter = Router();
orderRouter.post('/orders', async (req, res) => {
const { customerId, items, totalAmount } = req.body;
// 1. Write to private isolated database
const order = await orderRepository.create({
customerId,
items,
totalAmount,
status: 'PENDING',
});
// 2. Publish asynchronous Domain Event across service boundaries
await eventBus.publish('OrderCreated', {
orderId: order.id,
customerId,
items,
totalAmount,
timestamp: new Date().toISOString(),
});
res.status(201).json({ orderId: order.id, status: 'PENDING' });
});