Hey guys, curious to hear what people's thoughts w...
# sst
n
Hey guys, curious to hear what people's thoughts were around running an express server connected to the api-gw such that each route would have only one lambda function which handles routing etc? Heard the idea thrown around a bit recently, the main pro I can see for this is that it would reduce cold start times since the function would be getting used more, but that may be negligible if you had enough throughput on your lambdas? I imagine though there are other reasons like being able to use a bunch of express middleware and have access to that ecosystem?
a
This is the mono-lambda approach.
You can have a wildcard on the GW which routes everything into 1 lambda.
This is the opposite to what serverless proposes, to have “nano services”, but instead you want to have all into 1 single lambda.
We do that for our legacy application, which is built in PHP, and we run all that system in a mono-lambda with Vapor.
d
Just as a note, on very low and consistent traffic levels, a single lambda may have less cold starts, but the difference will drop significantly on spikes, as the single instance will get overloaded and new lambdas will start cold. As another note, the larger lambda (with express overhead) cold start time will be longer than if each lambda only had the code needed for that route.
As to the middleware question, you can have a look at
middy
. Its no replacement for express middleware, but it is similarly capable.
a
Yeah we use middy to pull SSM params in runtime.
d
There is really no issue with mono-lambda REST, since GraphQL is "mono-lambda required"
m
@Noah D We've had services where we did one lambda per domain. We called them fat-lambdas and found it worked really well for us
We didn't use wildcard routing on the APIgw choosing to still explicitly define the routes by HTTP method
Important to note that when going this route, you must define your
sst.Function
explicitly otherwise you get one lambda per route, even when it is the same handler.
n
Thanks for all the perspectives guys, is definitely something I am debating atm, but good to hear some pros and cons 🤔