Viaduct GraphQL Data-Oriented Service Mesh

repository·main·Indexed 41 days ago

https://github.com/airbnb/viaduct

A GraphQL-based data-oriented service mesh providing a unified interface for diverse data sources. It supports hosting business logic in a serverless-like fashion with a central schema and re-entrant logic composition. The framework includes a robust API stability model using annotations like @StableApi, @ExperimentalApi, and @InternalApi to manage binary compatibility via the Binary Compatibility Validator (BCV).

Tokens
140.8K
Snippets
299
Records
670
Agent score
43%

What's inside Viaduct

  1. What is Viaduct?

    main

    Viaduct is a multi-tenant GraphQL server designed to act as a data-oriented service mesh. It allows multiple independent teams to contribute their own schemas and resolvers (known as "tenant modules") which are then composed into a single, unified global schema served by a single runtime.

    Key benefits include:

    • Unified Interface: Provides a single GraphQL entry point for accessing diverse data sources.
    • Data-Centric Architecture: Organizes service interactions around data rather than remote procedure calls (RPCs), helping to avoid complex microservice dependency graphs.
    • Decentralized Ownership: Teams maintain their own data and logic via tenant modules, while the system provides a consistent global schema.
    • Separation of Concerns: The architecture maintains clear boundaries between the GraphQL execution engine, the tenant developer API, and the hosted application code.
  2. Overview of the Viaduct Engine API

    main
    The Viaduct Engine API is the primary interface used to build and run Viaduct modules. It provides the core interfaces, classes, and utilities required for GraphQL execution, including support for coroutines, derived fields, fragments, and observability.
  3. Viaduct Feature Support Roadmap

    main

    The Viaduct roadmap outlines the current status of features within the Engine and API. Features are categorized into several stages: Released, Preview, Under Development, Experimental, and Planned.

    Released Features

    • Resolvers MVP: Core resolver functionality.
    • Observability: Monitoring and observability capabilities.
    • Scopes: Scoping mechanisms for the engine.

    Preview Features

    • Multi-tenancy/multi-module support: Support for multiple tenants or modules.
    • Batch resolvers: Ability to resolve multiple items at once.
    • Mutations: Support for data mutations.
    • Development Server: An internal HTTP server for previewing Viaduct tenants.
    • Java API: A Java-based alternative to the Kotlin tenant API.

    Under Development

    • Subqueries: Advanced querying capabilities.
    • Object Mapping: Mapping generic object types (e.g., Thrift) to GraphQL types.
    • Coding Agent Support: Mechanisms to facilitate application creation via AI agents.
    • Build Time Validation: Mechanisms to validate schema violations during the build process.
    • Schema Customization: Support for custom root types.

    Experimental

    • Connections: Cursor-based pagination using fromList, fromSlice, and fromEdges builder utilities.

    Planned (H1 '26)

    • Factory Types: Kotlin-native way for tenants to share functions for constructing GRTs.
    • Named Fragments: Reusable GraphQL query parts.
    • Visibility: A @visibility directive to control internal module code access.
    • Subscriptions: Support for GraphQL Subscriptions.
    • Parent/Child Relationships: Hierarchical or associated data relationships across GraphQL types.
    • AI generated mock data: Automated generation of mock data for testing resolvers.
  4. Operating a Viaduct instance as a Service Engineer

    main

    Viaduct is designed with two distinct user roles. If you are building application logic (resolvers, schemas, etc.), refer to the Developers documentation.

    If you are a Service Engineer, your role involves managing the Viaduct service infrastructure. This includes:

    • Integrating Viaduct into your organization's web-serving stack (HTTP frameworks, message consumers).
    • Configuring tenant module composition for multi-tenancy.
    • Extending the schema with shared types and directives.
    • Integrating with dependency-injection (DI) frameworks.
    • Setting up observability, monitoring, and alerting.
  5. Use the Micronaut Viaduct Starter for GraphQL applications

    main

    The Micronaut Viaduct Starter is a minimal template for building Viaduct GraphQL applications using the Micronaut framework. It provides a bridge between Viaduct and Micronaut's dependency injection (DI) system, allowing you to use Micronaut annotations like @Singleton and @Factory within your Viaduct resolvers.

    Key capabilities include:

    • Full DI Support: Resolvers can have dependencies injected via Micronaut's DI container.
    • Production Ready: The application runs as a full Micronaut HTTP server.
  6. New features in Viaduct 0.32.0

    main

    Key updates in this release include:

    • Exception Hierarchy: ViaductException now implements TenantException.
    • Validation: Strict missing-resolver validation is performed at startup. DefaultSchemaValidator and ViaductServiceValidation (at CI-time) include two new OSS schema validation rules.
    • Bootstrapping: Added file-driven bootstrapping for demoapps and changes to the file-based bootstrapping API surface.
    • Annotations:
      • Node resolvers now require the @Resolver annotation.
      • providedVariables can now be populated from the @Variables nested class annotation.
    • KSP Support: Added KSP-based module config file generation and additional KSP fields to support schema-less bootstrapping.
  7. Understand Viaduct core concepts via the Star Wars demo

    main

    The Star Wars demo application illustrates how Viaduct's core building blocks compose into a single runnable server. The architecture is organized around tenants (e.g., universe and filmography). Each tenant owns a specific portion of the schema and its corresponding resolver code. These tenants compose together to form the complete system.

    Key concepts covered in this section include:

    • Schemas: The structural definition of the data.
    • Resolvers: The logic that fetches data for specific fields.
    • Scopes: The boundaries within which resolvers operate.
    • Global IDs: Unique identifiers used across the system.
    • Batching: Mechanisms to optimize data fetching and prevent N+1 problems.
  8. Architecture of the Viaduct Star Wars demo application

    main

    The Star Wars demo application demonstrates how to use Viaduct as a GraphQL runtime within a Kotlin and Spring Boot environment. The architecture is built around a multi-tenancy model where different logical modules (scopes) maintain isolated schemas and resolvers.

    Key architectural features include:

    • Runtime: Kotlin on Spring Boot using Viaduct.
    • Tenancy Model: Multiple logical modules (scopes) with isolated schemas and resolvers.
    • Data Layer: Uses in-memory data sets (e.g., StarWarsData) which are designed to be replaceable with persistent stores (SQL/NoSQL) without altering the public schema.
    • Performance & Stability: Implements batching, caching, and type-safe Global IDs to mitigate N+1 problems and ensure stable object references.
  9. Understand the Binary GraphQL Schema Encoding Format

    main

    The ViaductSchema binary format is a compact, efficient representation of GraphQL schemas designed for build-time tooling and runtime loading. It prioritizes fast, single-pass decoding with minimal heap allocations through deduplication and index-based references.

    Key Characteristics:

    • Compactness: Uses lookup tables (identifiers, source locations, etc.) and references them via 20-bit indices.
    • Self-Contained: Includes all necessary schema information for runtime.
    • Not for Archival: This is a working format; use GraphQL SDL for long-term storage.
    • Section-Based: The file is organized into sequential, 4-byte aligned sections (e.g., Header, Identifiers, Definitions).
  10. Evaluate if Viaduct is suitable for your GraphQL needs

    main

    Viaduct is designed to scale from small GraphQL servers to massive supergraphs. It emphasizes developer ergonomics and is suitable for both new projects and large-scale production environments.

    Key characteristics include:

    • Scalability: Proven to handle massive graphs and hundreds of tenants.
    • Modern Engine: A production-ready engine that supports evolving API patterns.
    • Batch Resolvers: A feature in the Modern API designed to smooth the adoption of the data-loader pattern, improving performance by batching requests.
  11. Use the Viaduct Tenant API to implement GraphQL behavior

    main

    The viaduct.tenant.api package is the primary interface for tenants integrating with the Viaduct Framework. Tenants use this API to define how their GraphQL schema behaves. Specifically, it provides the mechanisms to implement:

    • Field and Node @resolvers: Logic for resolving specific GraphQL fields or nodes.
    • Custom Access Checkers: Logic for enforcing security and access control rules on the schema.
  12. Overview of Custom Directives in Viaduct

    main

    Custom directives in Viaduct are schema annotations used to enhance GraphQL schemas with extra behavior and validation. Viaduct interprets these directives during the planning or execution phase, allowing you to express resolver hints, identity types, and visibility rules directly in your schema without requiring additional Kotlin code.

    Commonly used directives include:

    • @backingData: For sharing pre-fetched data between sibling field resolvers.
    • @scope: For controlling visibility of types/fields across multi-module boundaries.
    • @idOf: For type-safe Global ID handling.
    • @oneOf: For enforcing union-like constraints on input objects.
    • @connection: For marking Relay Connection types.
    • @edge: For marking Relay Edge types.