Skip to content

Pre-SIP: Spin Services #3811

Backlog
Backlog

Description

@lann

A Spin Service would be a way to hide external service configuration (auth, most notably) from guest code. It would be nice to represent these as named wasi:http/client imports (or similar), but for compatibility these services could be accessed via outbound HTTP, addressed via magic hostname, e.g. <service-name>.svc.spin.internal.

[variables]
github_token = { required = true, secret = true }

[service.github-api]
url = "https://api.github.com"
headers = { user-agent = "My-Github-App" }

[service.github.authentication]
type = "bearer"
value = "{{ github_token }}"

[component.github-client]
source = "github-client.wasm"
services = { github = "github-api" }
# Implied:
# allowed_outbound_hosts = ["https://github.svc.spin.internal"]

The above service would be invoked as https://github.svc.spin.internal/<path>, which would be translated to https://api.github.com/<path> with auth / headers injected.

The authentication section could be an open enum, with some baked-in types:

[service.ye-olde-service.authentication]
type = "basic"
username = "ye-olde-user"
password = "{{ ye_olde_password }}"

[service.never-heard-of-bearer-tokens.authentication]
type = "header"
header_name = "X-Api-Key"
value = "{{ api_key }}"

Other auth types could be supported directly by embedders with custom types or via middleware (below).

Extensions

While the initial design is driven mostly by common HTTP service auth patterns, services could be extended in a number of directions:

Middleware

More complex auth types (and other functionality) could be provided by outbound service middleware:

[service.uses-oauth]
url = "https://api.uses-oauth.com"
middleware = [{ component = "oauth-middleware" }]

[component.oauth-middleware]
source = "oauth-middleware.wasm"
variables = { client_id = "...", client_secret = "..." }

We might want to support only a single middleware component until dependency isolation lands.

Typed HTTP Services

External services could be associated with schema definitions to drive generation of service bindings:

Very rough sketch!

[service.openapi-service]
url = "https://api.openapi-service.com"
schema = { type = "openapi", path = "openapi_service.yaml" }

[service.grpc-service]
url = "https://api.grpc-service.com"
schema = { type = "grpc", path = "grpc_service.proto" }

[component.api-client]
source = "api-client.wasm"
services = ["openapi-service", "grpc-service"]

[component.api-client.dependencies]
"openapi-service:client" = { service_bindings = "openapi-service" }
"grpc-service:client" = { service_bindings = "grpc-service" }

And More...

  • Non-HTTP services; intercept wasi:sockets instead of wasi:http
  • Remote component-backed services; generated RPC bindings for inter-component calls

Activity

  1. radu-matei commented on Nov 25, 2026

    @radu-matei
    Member

    I'm very aligned with this direction; we've wanted something like this for a while, thank you for the proposal.

    I'd like to explore if we can use services as a starting point for unifying how we treat and describe internal application concerns with external application concerns:

    • internal application concerns: functionality that is implemented by an application developer (today defined as components in spin.toml), or functionality that Spin itself provides (configured per-component in spin.toml). This includes the Wasm components defined in spin.toml today, together with all the built-in capabilities of Spin: application variables, KV stores, SQLite databases, AI models, and their consumption by Wasm components.
    • external application concerns: this is functionality that is not implemented as part of the current Spin application (spin.toml in the current directory). This could be origins, external APIs, databases, storage buckets, AI models provided by external APIs that are used, depended on, or consumed by one or more components of the application, and are usually expressed and passed to components as opaque variables.

    While it is possible and we have evidence of developers building self-contained Spin applications (where the entirety of a particular workload is built and deployed as one Spin application), my experience indicates that the majority of developers build Spin applications that are part of a larger system, and components of the Spin application must almost always interact with the rest of the system.

    To me, this is an important reason to consider external application concerns (following the categorization above) and whether we have the opportunity to improve how these applications are built, configured, deployed, or inspected.

    Today, the interaction between internal and external concerns is implicit in component code and configuration. We can pass a component an endpoint and credentials, then allow outbound access, but the application definition tells us relatively little about what the dependency represents, or how it fits into the application.

    I think services could make these dependencies an explicit part of the application definition. They could give developers a way to describe parts of the surrounding system their application needs, and give Spin (and deployment platforms) enough information to help configure, connect, validate, or inspect those relationships.

    Declaring an external service would describe how an application consumes it; it would not imply that Spin becomes responsible for deploying or managing it.

    I would also like to explore whether the same model could describe functionality supplied within the application or Spin itself. We already have ways to configure and grant access to things like KV stores or SQLite databases, but each has its own convention. A service abstraction seems like an opportunity to bring these into a consistent model for describing what functionality is available, how it's configured, and which components consume it.

    Over time, this would give us a path to unify existing functionality and make it easier for platforms to introduce new capabilities.

    Rough sketch along the lines of the example you have above. Take this example conceptually, and consider the declaration / binding / configuration pattern rather than the actual syntax:

    [variables]
    github_token = { required = true, secret = true }
    
    [service.github-api]
    type = "http"
    url = "https://api.github.com"
    headers = { user-agent = "My-Github-App" }
    
    [service.github-api.authentication]
    type = "bearer"
    value = "{{ github_token }}"
    
    [service.cache]
    type = "key-value"
    
    [component.github-client]
    source = "github-client.wasm"
    
    [component.github-client.services]
    my-github-api = "github-api"
    my-kv-cache = "cache"

    In this sketch, github-client would call https://my-github-api.svc.spin.internal/... and open my-kv-cache through the existing KV API. The bindings give the component access to the declared services under those local names. The external HTTP dependency and the built-in KV capability follow the same declaration and access model, while retaining their respective interfaces.

    HTTP seems like a great first candidate. It would make sense to keep the initial implementation focused on HTTP while considering the broader changes.

  2. lann commented on Nov 25, 2026

    @lann
    ContributorAuthor

    One of my goals here is to keep scope under control for a first revision, but I agree that we should keep an eye on the opportunity to unify different service types (perhaps in a v3 manifest format?).

    Some thoughts on generalized services:

    • For the above sketch you can think of each service as having an implicit type = "http". That may even be a reasonable default in the long term but we would have the option to make type mandatory in a v3 manifest. Different flavors of service types:

      • Common service types: "http", "keyvalue", "sqlite"
      • Generic service types (always paired with some extra service definition): "openapi", "grpc"
      • Custom services types: any component interface, implemented either by a component in the application itself (in which case invocation would be analogous to service chaining) or expected to be implemented by the host (merged into the target environment?).
    • Abstractly, a service can represent a plain-name instance import, e.g. (import "my-service" (implements "some:package/interface") ...)

      • In a magical future where every library and language bindgen impl supports it, this could be the only representation.
      • In our current reality we compromise by exposing a number of alternative ways to address individual services, with <name>.svc.spin.internal as one common convention.
      • For existing interfaces that already use named instances (wasi:keyvalue, spin:sqlite), service names would map directly to those names.
    • "Middleware" is somewhat HTTP-specific; another way to frame it would be as an optional reference to a single adapter (?) component, which would export the service's interface, implemented in terms of host imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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