Back to Projects
Outside Inc.Full Stack Engineer2023-2024

Editorial Subgraph

A GraphQL Federation subgraph serving editorial content including articles, authors, collections, recipes, and podcasts to the Apollo Gateway.

TypeScriptApollo ServerApollo FederationPrismaPostgreSQLRedistype-graphql
Editorial Subgraph

The Challenge

Outside Inc.'s editorial content spans diverse formats—articles, recipes, gear reviews, podcasts, galleries, and video collections. This content needed to be served through a unified GraphQL API that could:

  • Support complex content relationships (authors, categories, tags)
  • Handle multiple content types with shared and unique fields
  • Integrate with the broader Apollo Federation architecture
  • Maintain performance under high traffic loads
  • Support both read and write operations from WordPress

Architecture

The Editorial Subgraph is one piece of a federated GraphQL architecture:

┌─────────────────────────────────────────────────────────────┐
│                    Apollo Gateway                            │
│              (Federated supergraph)                          │
└─────────────────────────────────────────────────────────────┘
        │                   │                   │
        ▼                   ▼                   ▼
┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│    Editorial    │  │    JWPlayer     │  │     User        │
│    Subgraph     │  │    Subgraph     │  │    Subgraph     │
└─────────────────┘  └─────────────────┘  └─────────────────┘
        │
        ▼
┌─────────────────────────────────────────────────────────────┐
│                     PostgreSQL                               │
│                  (AWS RDS + Read Replica)                    │
└─────────────────────────────────────────────────────────────┘
Federation Architecture

Technical Approach

Schema Design

The schema uses interfaces for shared content behavior. A base Content interface defines common fields (title, slug, description, published date, author, categories, tags) that all content types implement. Specific types like ContentArticle and Recipe extend this with their unique fields—articles have hero images and body content, while recipes have ingredients, instructions, and nutrition info.

Federation Entities

Content types are exposed as federation entities, allowing other subgraphs to reference and extend them. Each entity includes a reference resolver that fetches the full object when another subgraph needs to resolve a cross-service relationship.

Database Schema

The PostgreSQL schema supports complex relationships with proper indexing for performance. Articles link to authors, categories, and tags through junction tables. Soft delete support allows content recovery, and WordPress IDs are stored for synchronization.

Resolver Implementation

Resolvers use type-graphql decorators with DataLoader for N+1 query prevention. Field resolvers handle relationship loading efficiently by batching database queries, ensuring that fetching 100 articles with their authors results in just 2 queries rather than 101.

Caching Strategy

Response caching at the Apollo Server level reduces database load significantly. Cache hints are set per field—listings might cache for 1 minute while individual article data caches for 5 minutes. Redis provides the distributed cache storage.

Key Features

Content Synchronization

WordPress publishes to the subgraph via webhooks. When content is created or updated in WordPress, an upsert operation syncs the data to PostgreSQL, and the relevant cache entries are invalidated.

Soft Delete Support

Articles can be soft-deleted by setting a deletedAt timestamp rather than removing the row. This allows content recovery if needed while ensuring deleted content doesn't appear in queries.

Read Replica Support

High-read queries are routed to the PostgreSQL read replica, distributing load and improving response times for listing pages and search results.

Outcomes

The Editorial Subgraph successfully:

  • Unified content access — Single API serves all content types
  • Enabled federation — Content integrates with user and video data
  • Improved performance — Caching reduced database load by 80%
  • Supported migration — WordPress content syncs automatically
  • Maintained flexibility — Schema evolves without breaking clients

The subgraph handles thousands of requests per minute, serving content to the Headless Editorial frontend, Activity Feed, and various internal tools.