How nikunjkabariya/aws-microservices works
Project type and purpose
• This is a Serverless, event-driven microservices project for an e-commerce domain.
• It uses AWS Lambda for compute, API Gateway for REST endpoints, DynamoDB for persistence, Amazon EventBridge for event routing, SQS for queuing, and AWS CDK (TypeScript) for infrastructure-as-code.
File structure
• bin/aws-microservices.ts – CDK app entry point
• lib/ – CDK construct code:
– apigateway.ts
– aws-microservices-stack.ts (assembling the full stack)
– database.ts (DynamoDB tables)
– eventbus.ts (EventBridge bus)
– queue.ts (SQS queues)
– microservice.ts (Lambda + integration helpers)
• src/ – three independent microservices, each with its own package.json, Lambda handler (index.js), DynamoDB client (ddbClient.js), EventBridge client (eventBridgeClient.js) and configuration JSON:
– product
– basket
– ordering
• test/aws-microservices.test.ts – unit/integration test for the CDK stack
README for additional insights
• The reference architecture is a real-world e-commerce back end exposing three REST microservices (product, basket, ordering).
• Key patterns: REST + CRUD with API Gateway & Lambda, persistence in DynamoDB, decoupling via EventBridge, cross-service messaging via SQS, all wired by CDK.
a. Main components:
• Client (e.g., web/mobile front end or Postman)
• Amazon API Gateway – three resource paths (/product, /basket, /order)
• AWS Lambda functions – product-service, basket-service, ordering-service
• DynamoDB tables – ProductTable, BasketTable, OrderTable
• Amazon EventBridge – custom event bus
• AWS SQS – one or more queues for cross-service messages (e.g., order-process-queue)
• AWS CDK – the IaC layer that defines and deploys all resources
b. Relationships and data flow:
1. Client → API Gateway → specific Lambda (e.g., basket-service)
2. Lambda ↔ DynamoDB for CRUD operations
3. On critical actions (e.g., “checkout basket”), Lambda publishes an event to EventBridge
4. EventBridge rule routes events to SQS queue(s) and/or directly triggers subscribing Lambdas (ordering-service)
5. ordering-service consumes from SQS (or EventBridge) → updates OrderTable → may emit further events
6. CDK code ties all constructs together, specifying permissions, environment variables, event rules, and API mappings
c. Architectural patterns:
• Microservices – each business domain owns its own database and codebase
• Serverless – zero server management via Lambda and managed services
• Event-driven / pub-sub – loose coupling between basket and ordering
• Queue-based load leveling – SQS buffers spikes in event traffic
• Infrastructure as code – reproducible, version-controlled stack via CDK
d. Key technologies & libraries:
• AWS CDK (TypeScript) constructs in lib/
• AWS Lambda (Node.js) handlers in src/
• DynamoDB SDK (ddbClient.js)
• EventBridge SDK (eventBridgeClient.js)
• Jest for CDK/unit tests