Should I use a single, monolithic Lambda function or multiple Lambda functions with API Gateway?

I’ve seen a lot of discussion in various forums on whether it’s better to use a single, monolithic Lambda function (with its own routing logic) or multiple, single-purpose Lambda functions with API Gateway. Arguments in favor of a monolithic function are that it’s easier to manage, more performant, and easier to understand.

I disagree.

Automated tools such as CloudFormation, Terraform, and Serverless make managing one or many functions easy. The issue of Lambda cold starts is a bit overblown. And while a single function may seem conceptually simpler, any developer that needs to work with that function will need to understand more code to safely make changes, even if that code doesn’t directly apply to the task at hand.

I recommend multiple, single-purpose Lambda functions.

Because each function only does one thing, it’s easier to understand and easier to change safely. You’ll also reduce your blast radius when deploying changes. And you’ll have clear metrics on which functions are triggered most often and how much those functions cost your business.

I could go into much more detail on any of these topics — let me know what you’re most interested in via the responses.

If you find my work interesting, sign up for the Statics & Dynamics mailing list so you don’t miss a thing.