Introduction:
In a recent project, our team worked on optimizing a Node.js application that was originally hosted on an EC2 instance. The application experienced significant performance challenges, with response times exceeding 5 seconds per request. To enhance performance and reduce operational costs, we transitioned the application to Express.js on AWS Lambda. This migration not only brought response times down to under 1 second but also introduced a more scalable and cost-efficient architecture.
Why the Migration Was Necessary:
Our decision to move away from EC2 was driven by several key factors:
- Performance Bottlenecks: The existing EC2 infrastructure struggled to meet performance expectations, leading to slow response times.
- Faster API Responses: A target of under 1 second response time was essential for improving user experience.
- Cost Optimization: Running a dedicated EC2 instance was expensive, particularly during off-peak hours when resources were underutilized.
- Scalability Needs: AWS Lambda’s serverless nature allows for automatic scaling without manual intervention.
- Used AWS API Gateway to trigger the Express.js Lambda function.
- Containerized the application using AWS Lambda layers for better dependency management.
- Leveraged Lambda’s auto-scaling to enhance efficiency and eliminate manual scaling efforts.
- High DTO charges resulted from NAT gateway usage in the private subnet.
- CDN requests added to the overall expense, further impacting cost efficiency.
- Deployed Redis within the same private subnet to serve as a caching layer.
- Modified the Lambda function to first check Redis for cached files before fetching from S3.
- Stored frequently accessed files in Redis, ensuring near-instant responses.
- DTO costs were eliminated as requests remained within the private subnet.
- CDN input/output costs dropped to zero.
- Latency was significantly reduced, with Redis delivering sub-millisecond response times.
- Concurrent executions: Ensuring seamless auto-scaling.
- Invocation counts: Tracking Lambda function calls.
- Error rates (5XX, 4XX): Identifying and addressing failed requests.
- Success rates (2XX): Measuring successful responses.
- Response times: Reduced from 5 seconds (EC2) to under 1 second (Lambda + Redis).
No comments:
Post a Comment