T
tRPC

❓-help

Is there a way to split a trpc api across multiple lambdas ?

AEAhmed Eid8/19/2023
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 )
AEAhmed Eid8/19/2023
hmm, interesting but probably not the best approach IMO.
Ssachin8/19/2023
if you think there’s a better approach, feel free to do a PR
AEAhmed Eid8/20/2023
I'm not sure, I think lazy loading routes would be a much better approach than this, would you agree ?
AEAhmed Eid8/20/2023
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
AEAhmed Eid8/20/2023
let me know what you think ?
AEAhmed Eid8/20/2023
actouer routes sould look like this
No description
AEAhmed Eid8/20/2023
each router has 2 lambdas, 1 for queries and another for mutations. the routes trick doesn't seem to be working ...
Ssassythesasquatch_8/22/2023
Did you end up finding a solution to this, also using a similiar sst setup
Mmedv8/29/2023
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.
AEAhmed Eid9/11/2023
@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. it just need to be a /
Mmedv9/13/2023
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
AEAhmed Eid9/14/2023
lazy loading routers for TRPC would be an ideal solution for us too.

Looking for more? Join the community!

Recommended Posts
Can I alter the context in a procedure?Is there a proper way to do this? Mutating the `opts.ctx` directly seems wrongtRPC & getInitialPropsSo I am not using Next new App router but cant figure it out how to call a method during SSR with geGetting 413 error in Vercel when batching several queries (using Next pages router)Hi guys, I'm having a weird error on Vercel: "LAMBDA_RUNTIME Failed to post handler success responsQueries work but mutations do notOdd bug I'm experiencing with TRPC + react-query + the koa adapter. I just set everything up per docuseContext utils getData always returning undefinedI have my app set up with TRPC and when trying to call ` const utils = trpc.useContext();` `consTRPC Error HandlingI am using TRPC as my backend for my nextjs application. The one major problem i am facing is that, CORS issue with Lambda Handler (SST)no idea what's going on with this error. been stuck on it for way too long. i tried adding the test-TRPC API not working for production buildI am using Trpc and next in project, The App is fully functional with dev build , but api's giving 4Get object type using UseTRPCQueryResultthis code ```ts type playlistOutputData = UseTRPCQueryResult< inferRouterOutputs<AppRouter>["notifNeed help with type hinting a function that accepts a trpc client router```js interface CreateModelProps<GetResult> { name: string, procedures: DecoratedProcedureReDatabase error on examples-next-prisma-starterHi, im on node 18.16.0. I'm trying to clone and use this : https://github.com/trpc/examples-next-priSet server response headers from TRPC standalone adapterHi I am trying to implement my own authentication in Trpc. For this I need to create a session on tReturn TRPC Error from NextJS middlewareI am using trpc for my app's api but Im using NextJS middleware + upstash ratelimitting for.... welluseContext not InvalidatingWhat are the possible mistakes if useContext wont invalidate when doing the following: ```ts const uDeduping is broken, but is being batchedHi all, We're using TRPC for our React Native app, while doing some testing, I saw in my server logQuestion about trpc revalidation methodalright I have a question, why can tRPC detect changes from the DB and refetch. but when I mutate thHow can I enable experimental Suspense on NextJSO have a project with trpc (v.10^) and nextjs 13, and I wanna test the suspense query, but not show Examples of Vitest with React Testing LibraryDoes anyone have examples of how to mock data from tRPC procedure calls? I have client components thHow to refetch based on different eventI have a procedure that fetches all products, I have another one that deletes a project given it's IDockerizing in TRPCHi guys, I am developing a Next app with TRPC subscriptions/websockets and am running into issues tr