Juan Rodríguez

Microservices using NestJs & AWS

This project is a microservices-based API built with the NestJS framework. For inter-service communication, it utilizes the @nestjs/microservices library over the TCP transport layer. The architecture consists of a primary Gateway service (exposed on port 3000) that acts as the central orchestrator, routing incoming requests to two additional microservices, which listen on ports 3001 and 3002 respectively.
On the infrastructure side, all services are containerized and deployed as ECS tasks using the Fargate launch type, with their Docker images stored in Amazon ECR. The entire workload runs within a single VPC that spans two subnets—one public and one isolated—with all compute resources placed securely within the isolated subnet. To facilitate reliable internal communication, all tasks are registered under the same Cloud Map namespace, enabling seamless service discovery.
To ensure these isolated tasks can interact with critical AWS services without traversing the public internet, the isolated subnet is equipped with VPC endpoints: gateway endpoints for S3 and DynamoDB, and interface endpoints for ECR, ECR Docker, CloudWatch Logs, and CloudWatch Monitoring.
For external access, the Gateway service is exposed through an Application Load Balancer (ALB). This ALB is secured with an SSL/TLS certificate and is integrated with a Route53 Hosted Zone, allowing the API to be consumed via a custom domain over HTTPS.
The entire infrastructure is codified into four distinct stacks: one stack provisions the VPC and all shared resources, while each of the three microservices has its own dedicated stack, ensuring clear separation of concerns and maintainability.
Overall, this project effectively demonstrates my ability to design, implement, and deploy a resilient and secure microservices ecosystem using NestJS in conjunction with modern AWS best practices.

URL: juancrs.com/projects/microservices

Design structure
          
Users AWS Cloud ALB certificate DynamoDB Auto Scaling 1 Gateway Auto Scalings Tasks ECR VPC CloudWatch

CDK / Infrastructure

This code snippet demonstrates how to set up an infra stack. It includes the creation of a VPC, security group, interfaces, cluster ecs, namespace and certificate. All these resources will be needed for the other stacks.

    
export class InfraStack extends Stack { constructor(scope: Construct, id: string, props: Props) { super(scope, id, props); // Step 1: Create VPC with 2 subnets, one Public and one Isolated within 2 availability zones. // Step 2: Create Security group to allow HTTPS from VPC to endpoints (ECR, Logs). // Step 3: Add Endpoint to private connectivity within AWS // Gateway endpoint to S3 // Gateway endpoint to DynamoDB // The interface to ECR is needed to get the image of the service from ECR // Interface endpoint to ECR // Interface endpoint to ECR DOCKER // Interface endpoint to CLOUDWATCH_LOGS // Interface endpoint to CLOUDWATCH_MONITORING // Step 4: Create Cluster ECS in the VPC // Step 5: Create private namespace to service discovery // Step 6: Create hostedZone and certificate for domain } }