Skip to content

[DISCUSSION] How to expose an internal instance (e.g. Payload getPayload()) to another worker via service bindings? #1007

@AliSananS

Description

@AliSananS

Hi everyone,
I’m experimenting with a multi-worker architecture using @opennextjs/cloudflare and Cloudflare service bindings.

Goal:
Separate CMS logic (Payload) into a dedicated worker and use it from the frontend worker without going through public HTTP endpoints. Basically: can a custom worker expose something like a Payload instance (e.g. via getPayload()) so the frontend worker can call it directly?

Context:

  • ServiceBindings allow calling other workers without extra request cost
  • I have this working for simple functions:
export default {
  fetch: handler.fetch,
  foo: async (args: any) => `hello: ${args}`,
}

From the frontend worker, calling CMS.foo() works fine.

Problem:
When exporting a Payload instance (from getPayload()) inside a custom worker, bundling fails because of dependencies like file-type, sharp, streams, etc — basically Node-only APIs.
Is there something I'm missing when using custom worker? Because these APIs are accessible when running with opennextjs/cloudflare dev

Question:
Is there an official / recommended way to expose something like a Payload instance (or similar complex services) between workers using the custom worker entrypoint, instead of exposing everything through HTTP routes?

Or is the intended pattern to wrap all access with fetch endpoints and avoid sharing internal services entirely?

Extra notes:

  • Not talking about public REST access.
  • Trying to keep bundle size small and avoid double hops (frontend → public CMS URL → DB).

Any insights from the core team or real-world examples would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions