Is there a way to split a trpc api across multiple lambdas ?
How do I go about splitting my TRPC api across multiple lambdas, such that each lambda would load the minimum code it needs to run, (ideally the frontend should not be affected )
16 Replies
see this example
https://github.com/trpc/trpc/tree/main/examples/soa
GitHub
trpc/examples/soa at main · trpc/trpc
🧙♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - trpc/trpc
hmm, interesting
but probably not the best approach IMO.
if you think there’s a better approach, feel free to do a PR
I'm not sure, I think lazy loading routes would be a much better approach than this, would you agree ?
I had an idea which looks to be working, I'm using SST.
I have a lambda per router. and I have a combing router ( fake ) which just exports the type for the frontend.
I have attached some screenshots.
let me know what you think ?
actouer routes sould look like this
each router has 2 lambdas, 1 for queries and another for mutations.
the routes trick doesn't seem to be working ...
Did you end up finding a solution to this, also using a similiar sst setup
Need to explore this pretty soon as it is a non-starter for us and your idea looks pretty good. Very curious to hear what did not work and what you are doing now.
@sassythesasquatch_ pause looking into this for a while, will continue investigating.
@medv I believe
trpc
dot seperator was a blocker for me
https://trpc.io/docs/rpc#accessing-nested-procedures
it's not compatible with api gateway.HTTP RPC Specification | tRPC
Methods Type mapping
it just need to be a
/
Thanks for responding. We aren't looking to host these in separate lambdas on separate endpoints, instead the modularization will occur with nestjs lazy loaded modules. I'd imagine the process for us will be slightly different as we do need the full router to be present at runtime, except one that is capable of mapping the request shape to the appropriate router path, at which point the lazy loading will occur. If we do get to this, I will write back here in the future.
Relevant: https://github.com/trpc/trpc/issues/4129
GitHub
feat: Lazy load routers · Issue #4129 · trpc/trpc
Describe the feature you'd like to request Basically next/dynamic but for the backend. Recently our tRPC router has been growing significantly for many reasons but mostly due to heavy third par...
lazy loading routers for TRPC would be an ideal solution for us too.