Dynamic handler loading in @effect/rpc - recommended approach? #5867
Replies: 1 comment
-
|
@schickling your analysis is spot on. the const writeRef = yield* ResourceRef.from(
scope,
Effect.fnUntraced(function*(scope) {
const handlers = yield* entity.protocol.toHandlersContext(buildHandlers).pipe(...)
const server = yield* RpcServer.makeNoSerialization(entity.protocol, {...})
})
)
re: your alternatives -- the proxy handler pattern (single dispatch to a i didn't find any open PRs or roadmap items for first-class dynamic handler support. given how |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I'm exploring whether it's possible to dynamically load more handlers into a running
@effect/rpcserver. My use case involves adding new RPC handlers at runtime without restarting the server.Investigation Findings
After exploring the codebase, I found that dynamic handler loading is not currently supported out of the box. Here's what I discovered:
Current Architecture
readonly requests: ReadonlyMap<string, R>Potential Approaches I've Identified
1. ResourceRef Pattern (from @effect/cluster)
I noticed that
@effect/clusteruses aResourceRefpattern inentityManager.tsthat allows hot-swapping RPC servers:This seems like the most proven approach since it's already in production use.
2. Layer Reconstruction
Reconstruct the entire server with updated handler layers. Maintains type safety but requires connection draining.
3. Proxy Handler Pattern
Use a single dispatch handler that routes to dynamically registered implementations. Works with current design but loses RPC type safety.
Questions
@effect/rpc?Any guidance would be greatly appreciated!
This discussion was created with assistance from Claude Code
Beta Was this translation helpful? Give feedback.
All reactions