Skip to main content

Complete Microservice Example

Build a complete e-commerce order processing system using the Nx CDK Plugin.

Architecture Overview

A minimal e-commerce orders service composed of:

  • API Gateway + Lambda for REST endpoints
  • DynamoDB table for persistence
  • SNS topic and SQS queue for event-driven processing
  • Optional S3 bucket for artifacts

Data flow: 1) Client calls REST API (create order) 2) API Lambda writes to DynamoDB and publishes an event to SNS 3) SQS subscription delivers events to a worker Lambda 4) Worker processes tasks and updates state (DynamoDB/S3)

1) Generate a preset service

Use the Event Service preset as a foundation:

nx g @mhshahzad/nx-cdk-deploy:preset --name=orders --preset=event-service

2) Add resources (bundles)

Add an API endpoint and a DynamoDB table:

# API for REST endpoints
nx g @mhshahzad/nx-cdk-deploy:api-service --project=orders --name=orders-api

# DynamoDB for order state
nx g @mhshahzad/nx-cdk-deploy:dynamodb --project=orders \
--tableName=OrdersTable \
--partitionKey=id:string \
--sortKey=createdAt:number

Optionally add a bucket:

nx g @mhshahzad/nx-cdk-deploy:s3 --project=orders --bucketName=orders-artifacts

3) Configure environments

  • Set account/region per env in project config
  • Provide runtime settings via .env.dev, .env.staging, .env.prod

See:

4) Deploy

nx deploy orders --configuration=dev

The deploy executor synthesizes and deploys the stacks.

5) Verify

  • Check CloudFormation for stack completion
  • Find API endpoint output and test a POST/GET
  • Inspect DynamoDB items
  • Confirm SNS topic and SQS queue metrics

6) Iterate

  • Add more routes to the API
  • Publish more event types and create consumers
  • Adjust throughput, retention, and concurrency per env

7) Cleanup

Destroy the environment when done:

nx destroy orders --configuration=dev

See: destroy executor