#532 — December 17, 2020

Read on the Web

🙂  For every other newsletters I write, this is the final week of the year, but with Ruby 3.0 being released this week, Ruby is a special exception! Watch out for a special bonus issue during the holidays ;-)

This week, however, is a roundup of the most popular items of 2020 along with a feature and interview (don't miss it!) on using Ruby serverlessly on AWS Lambda.

Thanks for your continued support, and if you have anything suitable for the special Ruby 3.0 edition, reply and let me know!
__
Peter Cooper, your editor

Ruby Weekly

The most visited
Ruby Weekly items of 2020

1.  When Should You NOT Use Rails? — A practical list of examples where Rails doesn’t necessarily shine compared to the alternatives. Given the number of emails I get asking me to balance non-Rails and Rails content in this newsletter, I'm not surprised this was popular. At the same time, I hear Rails has some tricks up its sleeve that will take it to new places in 2021.

Noah Gibbs

2.  ▶️ Taking VS Code From Editor to IDE — I am surprised a video made it into the top links of the year. While Visual Studio Code is a powerful editor on its own, here we got to see how the addition of a few extensions can turn it into a more intelligent IDE. (13 minutes.)

Drifting Ruby

JetBrains RubyMine 2020.3 Has Been Released — New features include Git staging support, interactive hints in the debugger, better tab management, improvements for the latest Ruby version, Rails, code coverage, navigation, and more, all in RubyMine 2020.3.

JetBrains sponsor

3.  Effectively Using Materialized Views in Rails — Postgres’s views and materialized views provide easy alternative ways of looking at a database’s underlying data through the lens of a persistent query, and working with them in Rails is not too tricky.

Leigh Halliday

By the way, our Postgres newsletter also has a best of 2020 roundup this week :-)

4. A Proposal for 'Endless' Method Definitions.. That Made It! — I was a bit incredulous when this dropped on April 1st, but it came from a core team member, Matz quite liked the idea, and... it's actually ended up in Ruby 3.0, though with a different syntax than originally proposed.

Yusuke Endoh

5.  How to Dockerize a Rails Application“I had to hear Docker explained about 48,766 times before I finally grasped why it’s useful.” So if you needed that 48,767th time, this tutorial may be for you.

Jason Swett

6.  Digging Into Ruby 2.7's Changes — Built up from the official news and release notes, this is a deeper look at what each of the new Ruby 2.7 features and changes really meant, complete with short code examples. I hope we get a similar roundup for Ruby 3.0!

Ruby References

Wondering How You Should Optimize a Particular Postgres Query? — pganalyze uses auto_explain to automatically collect EXPLAIN plans. Identify slow sequential scans, sorts on disk & more.

pganalyze sponsor

Honorary mentions:

  1. Exploring Big-O Notation with Ruby
  2. GitLab On Its Migration from Unicorn to Puma
  3. How to Perform Concurrent HTTP Requests in Ruby and Rails
  4. 25 Reasons to Switch to Webpacker
  5. rails new --minimal: A Minimal Rails App Skeleton Generator

Yes, these go to eleven... ;-)

🎁 Ruby and Rails Go Serverless

I've been playing with various serverless platforms and systems (AWS Lambda mostly, but also Cloudflare Workers, Netlify Functions and OpenFaaS) and find them fantastic for running little bits of code in an ops-free style in the cloud. Set and forget type stuff. But when I saw Ken Collins talking about running entire Rails applications with the serverless model, I began to wonder just how viable it was.

Lambda Containers with Rails; A Perfect Match! — This is the article where I saw Ken really make his pitch for running Rails apps serverlessly. He also announced that Lamby now works with Lambda’s new support for deploying functions in container images.

Ken Collins

This article got me thinking that while we frequently link to things about how to use Ruby serverlessly, we never really explained the why so I wanted to ask Ken some questions...

Ken Collins is an AWS Serverless Hero and Principal Engineer at Custom Ink where he focuses on growing their DevOps culture within the Ecommerce teams using AWS-first well-architected patterns.

Ken is a huge advocate for, and pioneer of, running Ruby in serverless environments (AWS Lambda in particular) and we had some questions for him about how Ruby fares there:

Why should Rubyists consider running Ruby apps serverlessly?

Don't worry, I’m not here to pitch you on microservices or convince you to smash your beloved Rails application into hundreds of little function calls. AWS Lambda is a wonderful deployment target that can host your entire application, similar to Heroku, with little to no internal changes.

Lambda is a commoditized compute platform of the future. Event-driven and deeply integrated within AWS, it allows your Rails architecture to be completely reimagined atop fully managed infrastructure resources like API Gateway, SQS, S3, CloudWatch, VPC NAT Gateways, IAM, and so much more. Using Lambda can help you or your engineering teams learn to "program the cloud”.

What's the performance like? Are "cold starts" a problem?

Surprisingly excellent! From small infrequently accessed apps to ones that service many millions of requests a day, Rails will do just fine on Lambda. We've found it can meet or beat EC2 while providing better auto scaling options with a little cost reduction too.

If you have discounted AWS Lambda because of “cold starts” - please reconsider. First, if cold starts were a problem, you can essentially turn them off with a new feature called 'provisioned concurrency.' But I doubt you will ever need to. Second, the majority of Lambda’s compute lifecycle will have your Rails application fully loaded and warm. An application's 2 to 4 second initialization statistically disappears for avg, p95, and even p99 metrics in high traffic scenarios. Lastly, some may remember that using a VPC with AWS Lambda incurred significant start up penalties. This has been solved since September 2019 and using a VPC now has no startup time cost.

In other performance news, AWS just announced that Lambda was working out while staying at home and social distancing. A function can now have up to 10 gigabytes of disk space, 10 gigabytes of memory, and up to 6 vCPUs as memory scales. Since Lambda shards horizontally, akin to one process, we have found that most applications only need 1,792 megabytes of memory equal to 1 vCPU.

What does Lamby do and why is it necessary?

Lamby is a simple Rack adapter. It converts Lambda invocation events from different AWS sources like API Gateway or Application Load Balancers and converts them into Rack events. It essentially turns one hash into another.

Though technically not fancy, what this unlocks is kind of mind boggling. By integrating AWS directly to Rails' HTTP layer, we have essentially removed the need for any web server. This includes everything from Apache or NGINX all the way down to Puma or Webrick. As you explore Rails on Lambda, this pattern of evaporating concerns, will be a common theme.

Ruby didn't become a first class language on AWS Lambda till late in 2018 which hurt its early adoption for serverless use cases. Do you think Ruby has a long term future on serverless platforms?

No matter what happens, Ruby will always be available for Lambda thanks to their new container support and open runtime interface which has been open sourced for Ruby. Currently AWS provides official runtime images for Ruby 2.5 and 2.7, but if your needs ever differ, we can now bring our own OCI (v1 and upward) compatible images to Lambda with the same runtime guarantees.

I believe in AWS. I believe they will provide an official Ruby 3 runtime shortly after its release. I am also very thankful they have supported me and my open source work like Lamby. So if you ask me... they are here for us.

Ken Collins is an AWS Serverless Hero and Principal Engineer at Custom Ink. You can follow him on Twitter — @metaskills

🛠 Top 5 GitHub Repos We Linked To in 2020

Based on unique clicks from unique subscribers — no shenanigans here :-)

Ferrum: Headless Chrome Ruby API — If you've used Puppeteer or Playwright in Node.js, this is the same idea in Ruby. It works really well. I've used it on a few projects without complaint.

RubyCDP

Noticed: Notifications for Rails Apps — Supports database, email, Action Cable, Twilio, Slack, and custom delivery methods. There’s a 12 minute screencast showing it off too.

Chris Oliver

TruffleRuby: High Performance GraalVM-Powered Ruby — Built on GraalVM, TruffleRuby is an up and coming (well, I guess by now it’s just 'here') high performance Ruby implementation that passes all the RubyGems tests.

Oracle

Start 2021 Off Right, Finally Upgrade Your Rails Application with FastRuby.io

FastRuby.io | Rails Upgrade Services sponsor

SuperDiff: View Differences Between Complex Data Structures in RSpec — When you’ve got something that’s expected and what actually came back, distinguishing the difference between them can be a pain. This attempts to make it easier.

Elliot Winkler

Super Bombinhas: A Ruby-Powered Platform Game — We featured this twice this year as it keeps getting updates. For a Ruby powered game, it’s surprisingly slick and if you’re intrigued at making games (or maybe even just standalone graphical apps) in Ruby, the codebase is well worth scouring (as is the MiniGL library its creator has made).

Victor David Santos

💻 Jobs

Software Developer (Austin, TX) — We're a largely ex-Pivotal tech team looking for developers with all levels of experience. If you enjoy learning, collaborating, and creative problem solving then let's talk.

Stronghold Resource Partners

Rails Engineer - Top Consultancy (Fully Remote / India) — Highly-technical Rails/React/Node firm with a great work/life balance and a popular blog.

BigBinary.com

Find a Job Through Vettery — Create a profile on Vettery to connect with hiring managers at startups and Fortune 500 companies. It's free for job-seekers.

Vettery

ℹ️ Interested in running a job listing in Ruby Weekly? There's more info here.