Coursera Cuts Build Times by 83% Using AWS Codebuild, Amazon ECS
Onkar Naik
DevOps @Forescout ?? | Google Champion Innovator | AWS | DevOps | 3X GCP | 1X Azure | 1X Terraform | Ansible | Kubernetes | SRE | Jenkins | Tech Blogger ??
!! Hello Connections !!
? Welcome you all to the world of Cloud Computing ?
This Article is based on one of the case study of Global Cloud Leader that is Amazon Web Services ( AWS ) Cloud . In this Article we see about the case study of Coursera with AWS Cloud .
Coursera is an educational technology company with a mission to provide universal access to the world’s best curricula. The company partners with top universities and organizations worldwide to offer online courses for anyone to take, for free. Coursera has more than 13 million users from 190 countries enrolled and offers more than 1,000 courses from 119 institutions, everything from Programming in Python to Songwriting.
? Challenges faced by Coursera
- Coursera had a large monolithic application for processing batch jobs that was difficult to run, deploy, and scale.
- A new thread was created whenever a new job needed to be completed, and each job took up different amounts of memory and CPU, continually creating inefficiencies.
- A lack of resource isolation allowed memory-limit errors to bring down the entire application.
- The infrastructure engineering team attempted to move to a microservices architecture using Docker containers, but they ran into problems as they tried to use Apache Mesos to manage the cluster and containers—Mesos was complicated to set up and Coursera didn’t have the expertise or time required to manage a Mesos cluster.
?? Why Amazon Web Services ?
- Docker containers on Amazon EC2 Container Service (ECS) enabled Coursera to easily move to a microservices -based architecture.
- Each job is created as a container and Amazon ECS schedules the container across the Amazon EC2 instance cluster.
- Amazon ECS handles all the cluster management and container orchestration, and containers provide the necessary resource isolation.
?? What Benefits Coursera got by using AWS Cloud ?
- Ease of use: Because Amazon ECS setup is straightforward and it manages all of the details of the cluster, the team had a prototype up and running in under two months.
- Speed and agility: Time to deploy software changes went from hours to minutes, and each team can now develop and update its respective applications independently because the applications are resource isolated with no cross-dependencies.
- Scalable capacity: Auto Scaling groups allow the compute capacity to scale up to handle dynamic job loads.
- Operational efficiency: No extra infrastructure engineering time is spent installing software and maintaining a cluster—Amazon ECS handles everything from cluster management to container orchestration.
To host its website and support its rapidly expanding business, Coursera relies heavily on Amazon Web Services (AWS). Until recently, the company focused on setting up its backend services and AWS infrastructure. Now, it needed to streamline its front-end processes as well. “We wanted to improve the front-end developer experience and improve our website’s reliability and performance,” says Bryan Kane, senior engineer at Coursera.
? Challenged by Limited Build Capacity
Coursera’s website, a single-page application written in JavaScript, is hosted on Amazon Simple Storage Service (Amazon S3) and served using Amazon CloudFront.
To build and deploy its web application, the company used eight Jenkins machines running on Amazon Elastic Compute Cloud (Amazon EC2) instances. The Jenkins instances were spun up each morning and sat idle until there was a job. When a change was committed to GitHub, it would trigger Jenkins to build the JavaScript and upload it to Amazon S3. “This process worked well for a while,” says Kane. “But as our application code grew, builds began to take a long time.”
In addition, its web applications were deployed as a single monolithic build. A problem with one application would stop deployment of the entire build.
To improve build safety, Coursera broke up its monolithic web application into 50 individual applications containing different parts of the website that could be built and deployed separately. It also developed a new system to work with the 50 applications—however, this process also had issues.
?“Any time we needed a build of the entire web application, we had to start 50 different Jenkins jobs to build all the individual applications,” says Kane. “However, we didn’t have sufficient capacity to run 50 jobs at once, so they would queue up and it would take a long time to go through them.”?
??The Jenkins instances were also used to run tests, backend builds, and other scheduled jobs. These jobs were delayed during the application build, causing frustration for backend developers. “We were looking for a solution that would allow us to run jobs in parallel—so we wouldn’t need to wait for a job to finish to run the next one,” says Kane.??
?? Using AWS CodeBuild to Build and Deploy JavaScript
Coursera chose to use AWS CodeBuild to build its JavaScript applications because it wanted a managed build service that could scale automatically and process multiple builds concurrently. “It took us less than two weeks to set up our containers to run on AWS CodeBuild,” says Kane. “Now we can run 50 or 60 jobs in parallel, and the build time is only the time it takes for the longest application to build.”
The company also started using Amazon EC2 Container Service (Amazon ECS) to deploy its JavaScript—and then used AWS CodeBuild to automate this step as well. Along with building the JavaScript assets and uploading them to Amazon S3, AWS CodeBuild also creates a Docker container that includes the assets and uploads it to Amazon EC2 Container Registry (Amazon ECR).
“Now, whenever we want to deploy an application update, we use a tool that works with Amazon ECS to spin up a new service with the container running the new code,” says Kane.
As a further optimization, Coursera uses a custom build environment in its projects—and uses AWS CodeBuild for that also. Instead of using the standard Node.js container for its builds, it uses AWS CodeBuild to create a separate Docker container that includes the JavaScript dependencies as cache. The container is pushed to Amazon ECR and referenced in the project configuration.
“To build an application, all we need to do is retrieve the Docker image from the container registry, run the scripts, and upload to Amazon S3,” says Kane. “We don’t need to wait for the JavaScript dependencies to download because they are already pre-warmed in the container cache."
Increased Speed, Scalability, and Cost Savings Using AWS CodeBuild
By using AWS CodeBuild, Coursera has reduced its web-application build times by 83 percent while achieving a significant cost savings.
“With AWS CodeBuild, our application build now takes about 10 minutes; using Jenkins it used to take up to an hour,” says Kane. “To get the same performance on Jenkins would cost four times as much because we would need to spin up 50 Jenkins instances to have the builds finish that quickly.”
On average, the company runs 300–500 builds each day using AWS CodeBuild, and because the service scales continuously and processes multiple builds in parallel, builds are not left waiting in queue. “
If we needed to run 70 builds all at once, we could do so,” says Kane. “It’s great to be able to execute on demand and have elastic capacity that’s ready to go.”
AWS CodeBuild also supports continuous integration and continuous delivery (CI/CD) and has increased developer productivity by streamlining the QA process. Each time a production run is submitted, AWS CodeBuild builds a full staging environment that is ready to use for QA.
“If there are bugs, our team can fix them and iterate much more quickly,” says Kane. “Our staging environment makes it much easier to do that.”
Using containers for its web applications has also made builds more consistent and reliable.
“Having everything inside a Docker container that starts fresh each time provides build isolation,” says Kane. “Our developers are spending less time debugging builds that don’t run.”
With the benefits it has seen using AWS CodeBuild for its front-end platform, Coursera is considering other ways to use the service.
Kane says, “Next, we’re going to add some of our backend services to AWS CodeBuild and see what that looks like.”
?? Services of AWS Cloud Used by Coursera
AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to provision, manage, and scale your own build servers. CodeBuild scales continuously and processes multiple builds concurrently, so your builds are not left waiting in a queue. You can get started quickly by using prepackaged build environments, or you can create custom build environments that use your own build tools. With CodeBuild, you are charged by the minute for the compute resources you use.
?? Amazon ECS
Amazon Elastic Container Service (Amazon ECS) is a fully managed container orchestration service. Customers such as Duolingo, Samsung, GE, and Cookpad use ECS to run their most sensitive and mission critical applications because of its security, reliability, and scalability.
ECS is a great choice to run containers for several reasons. First, you can choose to run your ECS clusters using AWS Fargate, which is serverless compute for containers. Fargate removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design. Second, ECS is used extensively within Amazon to power services such as Amazon SageMaker, AWS Batch, Amazon Lex, and Amazon.com’s recommendation engine, ensuring ECS is tested extensively for security, reliability, and availability.
?? Amazon S3
Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides easy-to-use management features so you can organize your data and configure finely-tuned access controls to meet your specific business, organizational, and compliance requirements. Amazon S3 is designed for 99.999999999% (11 9's) of durability, and stores data for millions of applications for companies all around the world.
Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. CloudFront is integrated with AWS – both physical locations that are directly connected to the AWS global infrastructure, as well as other AWS services. CloudFront works seamlessly with services including AWS Shield for DDoS mitigation, Amazon S3, Elastic Load Balancing or Amazon EC2 as origins for your applications, and Lambda@Edge to run custom code closer to customers’ users and to customize the user experience. Lastly, if you use AWS origins such as Amazon S3, Amazon EC2 or Elastic Load Balancing, you don’t pay for any data transferred between these services and CloudFront.
?? Amazon ECR
Amazon Elastic Container Registry (ECR) is a fully-managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images. Amazon ECR is integrated with Amazon Elastic Container Service (ECS), simplifying your development to production workflow. Amazon ECR eliminates the need to operate your own container repositories or worry about scaling the underlying infrastructure. Amazon ECR hosts your images in a highly available and scalable architecture, allowing you to reliably deploy containers for your applications. Integration with AWS Identity and Access Management (IAM) provides resource-level control of each repository. With Amazon ECR, there are no upfront fees or commitments. You pay only for the amount of data you store in your repositories and data transferred to the Internet.
?? Amazon EC2
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.
" We can run 50 or 60 jobs in parallel, and the build time is only the time it takes for the longest application to build."
Python Developer at Deloitte USI | Ex - Tata Power
4 年Great work.. ??
Site Reliability Engineer
4 年Nice research Onkar Naik
Full Stack Developer - DevSecOps @IBM ? DevOps Practitioner ? Ex Intern @CommVault, HighRadius ? 2x GCP, 1x Microsoft, 1x RedHat Certified Engineer
4 年Frankly....didn't know Coursera has AWS on its backend! Thanks for this article!!
Consultant at Syniti
4 年Excellent work ??
DevOps Engineer at SmartBear
4 年Great Onkar Naik