Rails 7 Upgrade Case Study: Marketing automation platform

Business Requirement

Our client, a US-based organization, operates a marketing automation platform designed specifically for insurance agents. The platform was originally built with Ruby v2.3 and Rails v4, using PostgreSQL for data storage. Background jobs were managed by Sidekiq and Redis, while Slim was used for templating. The frontend relied on AngularJS with CoffeeScript. However, over time, this setup became increasingly challenging to maintain, exhibited performance issues, and struggled to keep up with modern tools and practices.

Challenges

Lack of Testing

The absence of a comprehensive testing framework made it tough to ensure the reliability of existing features and updates. Without sufficient test cases, there was always a higher risk of introducing bugs or breaking existing functionality during upgrades.

Security Vulnerabilities

The application was using very old version of Ruby and Rails, which had many known security issues. These outdated software components posed significant risks, as they could be exploited by malicious actors, compromising the integrity of the platform

Codebase Maintenance Issues

Maintaining the legacy codebase was a daunting task due to its complexity. Frequent changes and the addition of new features made it even harder for developers to manage and update the system efficiently.

Compatibility Issues

The older versions of Ruby and Rails were not compatible with modern tools and libraries, limiting development capabilities. This incompatibility hindered the adoption of new technologies and best practices, affecting the overall growth and improvement of the platform.

Performance Bottlenecks

Inefficient code and outdated technologies led to slow performance, negatively impacting user experience. Insurance agents using the platform experienced slower response times, which hampered their productivity.

No CI/CD Pipeline

There was no automated process for continuous integration and continuous deployment, which meant manual and error-prone deployments. This lack of a CI/CD pipeline increased the time and effort required for releases and updates, impacting overall efficiency.

Scalability Issues

The platform struggled to scale to handle increased loads, which affected its ability to grow with the business. Scalability issues limited the platform's capacity to accommodate more users and increased data, impacting its long-term viability.

Manual Deployment Practices

Manual deployments increased the risk of errors and downtime. These processes were time-consuming and prone to human error, leading to inconsistencies between different environments and potential issues during production deployments.

rails-upgrade-app.jpg

Objectives

The primary goals of this project were to upgrade Ruby from v2.3 to v3.3 and Rails from v4 to v7. We also aimed to containerize the application using Docker, automate infrastructure provisioning with Terraform, and deploy the application via AWS Elastic Container Service (ECS). These upgrades were intended to modernize the platform, improve performance, enhance security, and ensure scalability.

Our Approach

We started with a detailed analysis of the application to understand its dependencies and compatibility with newer versions of Ruby and Rails. We devised a step-by-step upgrade plan, running in parallel with Dockerization, to ensure minimal disruption. Incremental upgrades of Ruby and Rails were performed, addressing compatibility and performance issues along the way.

We automated infrastructure provisioning using Terraform, managing AWS resources efficiently. CI/CD pipelines were set up using GitHub actions to streamline the deployment process. Throughout the project, we conducted comprehensive testing and maintained detailed documentation to ensure reliability and support future enhancements. This structured approach allowed us to modernize the application, enhance its performance, and ensure scalability.

Solution Offered

Ruby and Rails Upgrade

Ruby Performance Enhancements: Upgrading from Ruby 2.3 to 3.3 brings significant performance optimizations. Ruby 3.0, is designed to be three times faster (3X) than Ruby 2.0, thanks to improvements in the interpreter and garbage collection.

Rails Optimizations: Rails 7 includes numerous performance enhancements, including faster database queries, improved caching, and reduced memory usage. Upgrading from Rails 4 to Rails 7 could result in a 20-50% performance boost in many applications.

Dockerization

The application was dockerized, enabling containerization for consistent development and deployment environments. Docker was also used for local development and testing, improving efficiency and reliability by replicating production environments locally. This approach ensured that the application behaved consistently across different environments, reducing the likelihood of environment-specific and performance issues.

Infrastructure as Code with Terraform

Terraform scripts were written to define and provision AWS infrastructure, automating the setup and management of infrastructure components. This included managing resources such as ECS clusters, load balancers, RDS instances, and networking components, ensuring consistent and repeatable infrastructure provisioning. The use of Terraform allowed for version-controlled and automated infrastructure management, which is crucial for maintaining stability and scalability.

Deployment via AWS ECS

AWS ECS was leveraged for efficient container orchestration and management. Dynamic scaling of EC2 instances by Auto Scaling Groups (ASG) based on load was enabled, allowing automatic scaling to handle varying traffic loads. EFS was automatically mounted for the storage of Widgets & Thumbnails, providing scalable storage solutions.

All secrets and API keys were securely stored in the SSM Parameter Store. SSL certificates issued by ACM ensured secure communication over the internet. Redis, used by Sidekiq for processing background jobs, was run by ElasticCache, improving performance and reliability. Finally, SSH keys were securely stored using S3, centralizing and securing access credentials.

Caching and Background Jobs

Rails 7 and Redis caching strategies significantly enhance data retrieval speeds. Cached data can be served much faster than fetching it from the database each time. Using Sidekiq and Redis for background jobs offloads time-consuming tasks from the main application thread, resulting in a more responsive application.

Benefits to Customer

  • Enhanced Security: Addressed vulnerabilities and implemented modern security practices, reducing the risk of exploitation.
  • Improved Performance: Significant performance improvements were achieved due to modern Ruby and Rails optimizations, resulting in faster response times.
  • Cleaner Codebase: The codebase was simplified, improving developer productivity and making future development easier.
  • Simplified Deployment: Dockerization ensured consistent environments across development, testing, and production, reducing deployment issues.
  • Detailed Documentation: Detailed documentation was created, making it easier for new developers to onboard and for future enhancements to be made.
  • Better Developer Experience: The use of modern tools and practices led to a better developer experience, fostering innovation.
  • Scalability: ECS enabled seamless scaling to handle varying loads, ensuring the application could grow with the business.
  • Automation: Terraform scripts automated infrastructure provisioning, reducing manual errors and speeding up deployment processes, leading to more reliable operations.

Conclusion

The RoR upgrade project was successfully completed. By leveraging Docker, Terraform scripting, and AWS ECS, the application is now better equipped to handle future growth and development with enhanced performance and reliability.

Your one-stop shop for expert RoR services.

Join 250+ companies achieving top-notch RoR development without increasing your workforce.