Middy is a middleware engine for simplifying your AWS Lambda code when using Node.js. We caught up with both the project’s creator and maintainer to ask a few questions:
How did the Middy project start?
It started in 2016 when Luciano was working with a company building everything on AWS using serverless tech. We were early adopters of this tech so AWS invited us to speak at AWS Summit 2017 to present our serverless use cases.
Lambda was one of the services we used the most (to write REST APIs and data integration pipelines). We realised our code had a lot of duplication and inconsistencies and it was getting harder to keep quality high. We were missing an abstraction that would allow us to easily reuse pieces of repetitive business logic: validation, data serialization and deserialization, authentication and authorization, etc.
We decided to create an abstraction layer to help us simplify our codebase, reduce duplication, and make things more consistent/manageable. A year later we published Middy, effectively a Lambda middleware framework for Node.js, as an open-source project — this is how it was born.
The project saw good traction in the open-source community and many devs started to contribute. After a while, but not before releasing v1.0.0, Luciano put out a call to help from the community — early adopter/contributor Will Farrell offered to take over leadership of the project. Since then he has been leading the efforts on Middy, delivering v2.0.0, with work underway on v3.0.0.
How do you use Middy in production systems yourself?
Will: At DataStream, we started using it just after the v1-alpha was released about 3 years ago. We were migrating from using Elastic Beanstalk to be more serverless. Our API was the first piece to use Middy. Since then we’ve fully migrated to serverless and every Lambda and Fargate container now use Middy. Interestingly, even our Fargate containers use Middy to keep the code clean and organised. As Lambda gets better and covers more use cases, this approach allows us to switch from fargate to Lambda quickly to meet the needs of the system and lower costs. We use nearly every “official” middleware provided from Middy.
Have you tried any of the other serverless platforms?
Will: I mostly stick to AWS, but have used Firebase for smaller one-off projects (the Auth + function + DB integration is really powerful, whilst being dev friendly). I’d like to try Cloudflare Workers with KV Store, they’re doing some really cool stuff over there.
Luciano: I have mostly been using AWS too, even though I had the opportunity to also work with Azure Functions for some professional projects. While I think Azure is doing a great job and improving every day, I have to admit that at the time (~2019) working with Azure Functions was, in some aspects, harder than working with AWS Lambda.
What use cases do you think Node, Middy and AWS Lambda is ideal for?
Middy is a middleware framework that allows you to structure your code in “layers” where every layer is fulfilling a specific responsibility: serialization / deserialization, validation, authentication, etc. This allows you to focus on your business logic by moving all these concerns outside from your handler code.
Its code is simple in design, it doesn’t have excessive dependencies, and it’s purpose built.
Unlike others, Middy also focuses on use cases like triggering Lambda from other services such as SQS and S3 and making the developer experience in these less used cases easier.
0 Comments