Ahmed Eid
Ahmed Eid16mo ago

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
sachin
sachin16mo ago
GitHub
trpc/examples/soa at main · trpc/trpc
🧙‍♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - trpc/trpc
Ahmed Eid
Ahmed EidOP16mo ago
hmm, interesting but probably not the best approach IMO.
sachin
sachin16mo ago
if you think there’s a better approach, feel free to do a PR
Ahmed Eid
Ahmed EidOP16mo ago
I'm not sure, I think lazy loading routes would be a much better approach than this, would you agree ?
Ahmed Eid
Ahmed EidOP16mo ago
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.
No description
No description
No description
No description
Ahmed Eid
Ahmed EidOP16mo ago
let me know what you think ?
Ahmed Eid
Ahmed EidOP16mo ago
actouer routes sould look like this
No description
Ahmed Eid
Ahmed EidOP16mo ago
each router has 2 lambdas, 1 for queries and another for mutations. the routes trick doesn't seem to be working ...
Sassy The Sasquatch
Did you end up finding a solution to this, also using a similiar sst setup
medv ❄
medv ❄16mo ago
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.
Ahmed Eid
Ahmed EidOP15mo ago
@sassythesasquatch_ pause looking into this for a while, will continue investigating.
Ahmed Eid
Ahmed EidOP15mo ago
@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
Ahmed Eid
Ahmed EidOP15mo ago
it just need to be a /
medv ❄
medv ❄15mo ago
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.
medv ❄
medv ❄15mo ago
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...
Ahmed Eid
Ahmed EidOP15mo ago
lazy loading routers for TRPC would be an ideal solution for us too.