Two key optimizations were implemented to reduce EC2 instance costs and improve operational efficiency for backend services.
Optimization 1: Consolidating Arxena Backend Python Instances
- Previous Setup: The Arxena Backend Python service was initially distributed across multiple smaller EC2 instances: one
t2.micro, twot2.small, and onet2.medium. This configuration had a combined on-demand cost of $0.104 per hour. - New Setup: To simplify management and potentially optimize resource utilization, these instances were consolidated into a single
t2.largeinstance. - Cost Impact: The new
t2.largeinstance costs $0.0928 per hour. This change resulted in a direct hourly saving of $0.0112, representing a 10.8% reduction in hourly costs for this service.
Cost Breakdown: Arxena Backend Python
| Configuration | Instance Type | Count | On-Demand Price/hr | Total Cost/hr |
|---|---|---|---|---|
| Original | t2.micro |
1 | $0.0116 | $0.0116 |
t2.small |
2 | $0.023 | $0.046 | |
t2.medium |
1 | $0.0464 | $0.0464 | |
| Original Total | $0.104 | |||
| New | t2.large |
1 | $0.0928 | $0.0928 |
| New Total | $0.0928 | |||
| Savings | $0.0112/hr | |||
| Savings % | 10.8% |
Optimization 2: Decoupling Build and Serve Processes for NestJS (Twenty CRM) Application
- Previous Setup: The NestJS (Twenty CRM) application and its CI/CD build process were both handled on a single
t2.largeEC2 instance. This led to two main issues:- Performance Disruption: During CI/CD tasks, high CPU and RAM usage significantly impacted the live application's performance.
- Cost Inefficiency: The
t2.largeinstance was oversized for simply serving the application when builds were not running, leading to unnecessary expenditure.
- New Setup: To address these issues, the application serving and build processes were decoupled:
- The application is now served from a smaller, more appropriately sized
t2.smallinstance. - A bash script was developed to manage deployments: it provisions a
t2.largeinstance from an existing Amazon Machine Image on-demand for the build process, transfers the compiled application files using SCP to thet2.smallserving instance, and then terminates the temporaryt2.largeinstance once the build is complete.
- The application is now served from a smaller, more appropriately sized
- Cost Impact (Application Serving): By rightsizing the application server from a
t2.large(costing $0.0928/hr) to at2.small(costing $0.023/hr), the continuous running cost for the application server has been significantly reduced. This yields an hourly saving of $0.0698, a 75% reduction in the server's operational cost. The temporaryt2.largeinstance used for builds operates for only a few minutes during deployments, which occur occasionally, making its contribution to overall costs negligible.
Cost Breakdown: NestJS (Twenty CRM) Application Server
| Configuration | Instance Type | Count | On-Demand Price/hr | Total Cost/hr |
|---|---|---|---|---|
| Original | t2.large |
1 | $0.0928 | $0.0928 |
| Original Total | $0.0928 | |||
| New | t2.small |
1 | $0.023 | $0.023 |
| New Total | $0.023 | |||
| Savings | $0.0698/hr | |||
| Savings % | 75% |