paint-brush
When You Need More Power Than Lambda Providesby@johnjvester

When You Need More Power Than Lambda Provides

by John VesterJune 24th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Explore the challenges and lessons learned in transitioning to a cloud-native architecture, including why AWS Lambda fell short and how Heroku's Performance-L RAM dynos offered a better solution. Discover practical insights for optimizing cloud performance and reducing DevOps workload.
featured image - When You Need More Power Than Lambda Provides
John Vester HackerNoon profile picture


Navigating toward a cloud-native architecture can be both exciting and challenging. The expectation of learning valuable lessons should always be top of mind as design becomes a reality.


In this article, I wanted to focus on an example where my project seemed like a perfect serverless use case, one where I’d leverage AWS Lambda. Spoiler alert: it was not.

Rendering Fabric.js Data

In a publishing project, we utilized Fabric.js—a JavaScript HTML5 canvas library—to manage complex metadata and content layers. These complexities included spreads, pages, and templates, each embedded with fonts, text attributes, shapes, and images. As the content evolved, teams were tasked with updates, necessitating the creation of a publisher-quality PDF after each update.


We built a Node.js service to run Fabric.js, generating PDFs and storing resources in AWS S3 buckets with private cloud access. During a typical usage period, over 10,000 teams were using the service, with each contributor sending multiple requests to the service as a result of manual page saves or auto-saves driven by the Angular client.


The service was set up to run as a Lambda in AWS. The idea of paying at the request level seemed ideal.

Where Serverless Fell Short

We quickly realized that our Lambda approach wasn’t going to cut it.


The spin-up time turned out to be the first issue. Not only was there the time required to start the Node.js service, but preloading nearly 100 different fonts that could be used by those 10,000 teams caused delays too.


We were also concerned about Lambda’s processing limit of 250 MB of unzipped source code. The initial release of the code was already over 150 MB in size, and we still had a large backlog of feature requests that would only drive this number higher.


Finally, the complexity of the pages—especially as more elements were added—demanded increased CPU and memory to ensure quick PDF generation. After observing the usage for first-generation page designs completed by the teams, we forecasted the need for nearly 12 GB of RAM. Currently, AWS Lambdas are limited to 10 GB of RAM.


Ultimately, we opted for dedicated EC2 compute resources to handle the heavy lifting. Unfortunately, this decision significantly increased our DevOps management workload.

Looking For a Better Solution

Although I am no longer involved with that project, I’ve always wondered if there was a better solution for this use case.


While I appreciate AWS, Google, and Microsoft providing enterprise-scale options for cloud-native adoption, what kills me is the associated learning curve for every service. The company behind the project was a smaller technology team. Oftentimes teams in that position struggle with adoption when it comes to using the big three cloud providers.


The biggest challenges I continue to see in this regard are:

  • A heavy investment in DevOps or CloudOps to become cloud-native.
  • Gaining a full understanding of what appears to be endless options.
  • Tech debt related to cost analysis and optimization.


Since I have been working with the Heroku platform, I decided to see if they had an option for my use case. Turns out, they introduced large dynos earlier this year. For example, with their Performance-L RAM dyno, my underlying service would get 50x the compute power of a standard Dyno and 30 GB of RAM. The capability to write to AWS S3 has been available from Heroku for a long time too.

V2 Design In Action

Using the Performance-L RAM dyno in Heroku would be no different (at least operationally) than using any other dyno in Heroku. To run my code, I just needed the following items:



After navigating to the source code folder, I would issue a series of commands to log in to Heroku, create my app, set up my AWS-related environment variables, and run up to five instances of the service using the Performance-L dyno with auto-scaling in place:


heroku login
heroku apps:create example-service
heroku config:set AWS_ACCESS_KEY_ID=MY-ACCESS-ID AWS_SECRET_ACCESS_KEY=MY-ACCESS-KEY
heroku config:set S3_BUCKET_NAME=example-service-assets
heroku ps:scale web=5:Performance-L-RAM
git push heroku main


Once deployed, my example-service application can be called via standard RESTful API calls. As needed, the auto-scaling technology in Heroku could launch up to five instances of the Performance-L Dyno to meet consumer demand.


I would have gotten all of this without having to spend a lot of time understanding a complicated cloud infrastructure or worrying about cost analysis and optimization.

Projected Gains

As I thought more about the CPU and memory demands of our publishing project—during standard usage seasons and peak usage seasons—I saw how these performance dynos would have been exactly what we needed.


  • Instead of crippling our CPU and memory when the requested payload included several Fabric.js layers, we would have had enough horsepower to generate the expected image, often before the user navigated to the page containing the preview images.
  • We wouldn’t have had size constraints on our application source code, which we would inevitably have hit in AWS Lambda limitations within the next 3 to 4 sprints.
  • The time required for our DevOps team to learn Lambdas first and then switch to EC2 hit our project’s budget pretty noticeably. And even then, those services weren't cheap, especially when spinning up several instances to keep up with demand.


But with Heroku, the DevOps investment would be considerably reduced, placed into the hands of software engineers working on the use case. Just like any other dyno, it’s easy to use and scale up the performance dynos either with the CLI or the Heroku dashboard.

Conclusion

My readers may recall my mission statement, which I feel can apply to any IT professional:


“Focus your time on delivering features/functionality that extends the value of your intellectual property. Leverage frameworks, products, and services for everything else.” - J. Vester


In this example, I had a use case that required a large amount of CPU and memory to process complicated requests made by over 10,000 consumer teams. I walked through what it would have looked like to fulfill this use case using Heroku's large dynos, and all I needed was a few CLI commands to get up and running.


Burning out your engineering and DevOps teams is not your only option. There are alternatives available to relieve the strain. By taking the Heroku approach, you lose the steep learning curve that often comes with cloud adoption from the big three. Even better, the tech debt associated with cost analysis and optimization never sees the light of day.


In this case, Heroku adheres to my mission statement, allowing teams to focus on what is likely a mountain of feature requests to help product owners meet their objectives.


Have a really great day!