A blazing-fast, polyglot microservices ecosystem with unified GraphQL gateway and enterprise-grade database migrations
Welcome to the GraphQL Gateway Project - a next-generation microservices platform that combines the power of unified GraphQL APIs with the flexibility of polyglot microservices. Built for scale, designed for developers, and engineered for production.
- π Unified GraphQL Gateway: Single endpoint that aggregates multiple backend services seamlessly
- π₯ Hot-Reloading: Add new services during runtime without any service disruption
- π¨ Schema Visualization: Beautiful, interactive UI for exploring GraphQL schemas
- πΎ Persistent Storage: Service metadata and schema information stored with reliability
- ποΈ Advanced Migrations: Enterprise-grade MongoDB migration system with CLI tools
- π Polyglot Architecture: Services in TypeScript, Rust, Go, Python - all working together harmoniously
- π§ Technology: TypeScript, Node.js, Apollo Federation
- π― Purpose: Aggregates and proxies GraphQL schemas from multiple services
- β¨ Features: Schema stitching, hot-reloading, error handling, rate limiting
- π Endpoints: Unified GraphQL API with interactive playground
- π§ Technology: Rust, Axum, async-graphql, MongoDB
- π― Purpose: High-performance product catalog and record management
- β¨ Features: CRUD operations, media handling, taxonomy support, migrations
- β‘ Performance: Blazing-fast queries with type safety guarantees
- ποΈ MongoDB Migrator: Reusable migration framework for all services
- π Common Types: Shared data structures and utilities
- π οΈ Developer Tools: CLI utilities and helper functions
Enterprise-grade database evolution with zero-downtime deployments
- β π Auto-Discovery: Migrations register themselves using inventory macros
- β π Service Isolation: Each service maintains its own migration state
- β π οΈ Rich CLI Tools: Comprehensive command-line interface for migration management
- β β©οΈ Rollback Support: Bidirectional migrations with proper error handling
- β π‘οΈ Type Safety: Full Rust compile-time guarantees for data integrity
- β π Production Ready: Dry-run, planning, backup support, and zero-downtime deployments
# π Check migration status across all services
cargo run migrate status
# β¬οΈ Apply all pending migrations
cargo run migrate up
# β¬οΈ Rollback the last migration
cargo run migrate down
# π Show detailed migration plan
cargo run migrate plan
# π Discover available migrations
cargo run migrate discover
- π MongoDB Migrator Framework - Core migration system
- ποΈ Records Service Migration Guide - Service-specific guide
- β‘ Migration Quick Reference - Command cheat sheet
Before you begin, ensure you have:
- Node.js 18+ - Install Node.js
- Rust 1.70+ - Install Rust
- MongoDB - Install MongoDB or use MongoDB Atlas
- Docker (optional) - Install Docker
-
π₯ Clone the Repository
git clone <repository-url> cd graphql-gateway
-
βοΈ Environment Setup
# Copy environment templates cp packages/gateway/.env.example packages/gateway/.env cp packages/services/records/.env.example packages/services/records/.env
-
π Start the Gateway
cd packages/gateway npm install npm run dev
-
π¦ Start the Records Service
cd packages/services/records cargo run
-
π Explore the APIs
- Gateway Playground: http://localhost:4000/graphql
- Records Service: http://localhost:8080/graphql
- Health Checks: Both services expose
/health
endpoints
# Build and start all services
docker-compose up --build
# Or start individual services
docker-compose up gateway records-service
During development the gateway can start certain background workers inside the main Node.js process for convenience.
- API key usage consolidator: runs every
API_KEY_USAGE_FLUSH_INTERVAL_MS
to drain Redis counters into Postgres. - Defaults: in dev (
NODE_ENV !== 'production'
) this worker starts automatically. - Toggle: set
START_API_KEY_USAGE_WORKER=0
to disable.
Example:
# Start dev server without the in-process consolidator
START_API_KEY_USAGE_WORKER=0 pnpm run dev:admin
Ideas and enhancements on our roadmap
- π¦ Cached Strategy: Return last known state when remote schema fetch fails
- ποΈ Drop Strategy: Remove failed endpoints from root schema (current default)
- π Graceful Degradation: Partial schema loading with service health indicators
- π Advanced Authentication: OAuth2, JWT, API key management
- π Real-time Analytics: GraphQL query metrics and performance monitoring
- π― Smart Caching: Intelligent query result caching with TTL
- π Query Optimization: Automatic query analysis and optimization suggestions
Scalable, event-driven architecture that separates external API interactions from internal processing
This section illustrates a production-ready system where the GraphQL Gateway serves as the primary API layer for external clients, while internal processing leverages an asynchronous, event-driven backbone using Kafka.
The diagram below showcases a modern architecture that decouples external API interactions from internal, event-based communication:
π External Clients (Web/Mobile/API)
β
βΌ
βββββββββββββββββββββ
β π GraphQL Gatewayβ
β (External API) β
βββββββββββ²ββββββββββ
β (GraphQL Queries/Mutations)
ββββββββββββ΄βββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββ
β π¦ Records β β π Categories β
β Service β β Service β
β (Rust) β β (Go) β
ββββββββββ¬βββββββββ ββββββββββββ¬ββββββββ
β β
βΌ βΌ
ββββββββββ΄ββββββββββ βββββββββββ΄βββββββββββ
β π MongoDB β β π PostgreSQL β
ββββββββββββββββββββ ββββββββββββββββββββββ
β (Events) β
ββββββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββ
β π Kafka / NATS (Event Bus) β
βββββββββββββββββββ¬βββββββββββββββββ
β (Consume Events)
βΌ
ββββββββββββββββββββββββββββββββββββ
β β‘ Event Processor(s) β
β (Analytics, Notifications, etc.) β
β (TypeScript/Java) β
ββββββββββββββββββββββββββββββββββββ
The Gateway serves as the single source of truth for all external clients. It provides:
- π Unified GraphQL API with schema stitching
- π‘οΈ Authentication & Authorization
- π¦ Rate limiting and request throttling
- π Request routing and load balancing
- π API monitoring and analytics
Each service is a self-contained business unit with clear responsibilities:
-
π¦ Records Service (Rust)
- Core business logic for product record management
- Optimized for performance and memory safety
- MongoDB integration with advanced querying
-
π Categories Service (Go)
- Manages data taxonomies and hierarchical categories
- Built for high-concurrency read operations
- PostgreSQL for relational data integrity
Asynchronous communication for scalability and resilience:
- π‘ Event Publishing: Services emit domain events
- π Loose Coupling: Services evolve independently
- π Horizontal Scaling: Process events in parallel
- π‘οΈ Fault Tolerance: Retry mechanisms and dead letter queues
Specialized background services for non-blocking operations:
- π§ Notification Service: Email, SMS, push notifications
- π Analytics Pipeline: Data aggregation and insights
- π Search Indexing: ElasticSearch synchronization
- ποΈ Data Warehousing: ETL processes for business intelligence
sequenceDiagram
participant Client
participant Gateway
participant RecordsService
participant MongoDB
Client->>Gateway: createRecord mutation
Gateway->>RecordsService: Forward GraphQL request
RecordsService->>MongoDB: Save record data
MongoDB-->>RecordsService: Confirm save
RecordsService-->>Gateway: Return success + record ID
Gateway-->>Client: GraphQL response
Perfect for: User-facing interactions requiring immediate feedback
sequenceDiagram
participant RecordsService
participant Kafka
participant EmailProcessor
participant AnalyticsProcessor
RecordsService->>Kafka: Publish "RecordCreated" event
Kafka->>EmailProcessor: Consume event
Kafka->>AnalyticsProcessor: Consume event
EmailProcessor->>EmailService: Send welcome email
AnalyticsProcessor->>DataWarehouse: Update metrics
Perfect for: Background tasks, analytics, notifications, and data processing
# π¦ Install dependencies for all services
npm run bootstrap # or manually install each service
# π Start development mode with hot-reload
npm run dev:all
# π§ͺ Run tests across all services
npm run test:all
# π¨ Format code consistently
npm run format:all
# π Lint and check code quality
npm run lint:all
# Gateway tests (TypeScript)
cd packages/gateway
npm test
npm run test:integration
# Records service tests (Rust)
cd packages/services/records
cargo test
cargo test --release # Performance tests
# End-to-end tests
npm run test:e2e
- TypeScript: ESLint + Prettier for consistent code style
- Rust: rustfmt + clippy for idiomatic Rust code
- GraphQL: Schema validation and breaking change detection
- Git Hooks: Pre-commit hooks for automated quality checks
Each service exposes comprehensive health endpoints:
# Gateway health
curl http://localhost:4000/health
# Records service health
curl http://localhost:8080/health
# Detailed health with dependencies
curl http://localhost:4000/health/detailed
- GraphQL Metrics: Query performance, error rates, schema usage
- Service Metrics: Request latency, throughput, error rates
- Database Metrics: Connection pools, query performance
- Migration Metrics: Success rates, execution times
// Structured logging example
logger.info('Record created', {
recordId: record.id,
userId: context.user.id,
duration: '23ms',
metadata: { source: 'api' },
});
Optimizations included for sustained traffic (hundreds of millions of requests/day):
Path | Mechanism | Config | Storage Pattern |
---|---|---|---|
Usage stats | In-memory aggregation + timed flush | USAGE_FLUSH_INTERVAL_MS , USAGE_BUFFER_MAX_KEYS |
Batched INSERT ... ON CONFLICT |
Audit logs | In-memory queue + size/time flush | AUDIT_FLUSH_INTERVAL_MS , AUDIT_BUFFER_MAX |
Multi-row INSERT chunks |
Flush failures requeue data to avoid loss. On shutdown, buffers force-flush.
Exposed instruments (per service label):
buffer.size{service="usage|audit"}
buffer.flush.duration.ms{service="usage|audit"}
buffer.flush.rows{service="usage|audit"}
buffer.flush.failures{service="usage|audit"}
Migration 1759000000000-AddPerformanceIndexes
adds supporting indexes; 1759000001000-PartitionAuditLogs
introduces optional monthly partitioning of audit_logs
by createdAt
.
Retention cleanup automatically drops expired partitions when partitioning is enabled; otherwise it performs batched deletes driven by retention metadata.
The gateway supports MessagePack as a transport optimization.
Quick facts:
- Per-service toggle: enable
useMsgPack
in Admin UI to turn on downstream MsgPack responses. - Client opt-in: send header
x-msgpack-enabled: 1
to receive MsgPack-encoded GraphQL responses from the gateway. - Transparent internal decode: gateway decodes downstream MsgPack back into normal JS objects before stitching.
- Fully backwards compatible: no header, no change; services default to disabled.
Detailed documentation: packages/gateway/docs/MSG_PACK_SUPPORT.md
.
USAGE_FLUSH_INTERVAL_MS=5000
USAGE_BUFFER_MAX_KEYS=500
AUDIT_FLUSH_INTERVAL_MS=5000
AUDIT_BUFFER_MAX=1000
- Alert if
buffer.size
grows persistently (ingestion lag) - Tune flush interval downward if each flush processes large batches (>5k rows)
- Pre-create future audit partitions monthly via
SELECT create_audit_logs_partition(<first_of_month>)
- For extreme retention volumes, consider tablespace-level partition storage & WAL compression
- Adaptive flush (shorter interval as buffer utilization rises)
- Optional durable local write-ahead journal before buffering
- Sampling / dynamic throttling for homogeneous low-risk audit entries
We welcome contributions! Here's how to get involved:
- π΄ Fork the repository
- π Create a feature branch:
git checkout -b feature/amazing-feature
- β¨ Make your changes: Follow our coding standards
- π§ͺ Add tests: Ensure your changes are well tested
- π Update docs: Keep documentation current
- β
Commit changes:
git commit -m 'feat: add amazing feature'
- π Push to branch:
git push origin feature/amazing-feature
- π¬ Open Pull Request: Describe your changes thoroughly
- Follow existing code patterns and architecture
- Write comprehensive tests for new features
- Update GraphQL schema documentation
- Ensure backward compatibility
- Use
cargo fmt
andcargo clippy
- Write unit and integration tests
- Add database migrations when needed
- Document public APIs thoroughly
- Keep README files up-to-date
- Add inline code comments for complex logic
- Include examples for new features
- Update architecture diagrams when relevant
- π Bug Fixes: Help us squash bugs and improve stability
- β¨ New Features: Add exciting new capabilities
- π Documentation: Improve guides and examples
- π§ͺ Testing: Expand test coverage and scenarios
- π¨ UI/UX: Enhance GraphQL playground and tools
- β‘ Performance: Optimize queries and service performance
- GraphQL Official Docs - Learn GraphQL fundamentals
- Rust Book - Master Rust programming
- MongoDB Docs - Database best practices
- Apollo Federation - Advanced GraphQL patterns
- Microservices with GraphQL - Architecture patterns
- Event-Driven Architecture - Design principles
- Rust for JavaScript Developers - Language transition guide
- GraphQL Playground - Interactive API explorer
- VS Code GraphQL Extension - Enhanced development experience
- Rust Analyzer - Rust language server
- MongoDB Compass - Database GUI
This project is licensed under the MIT License - see the LICENSE file for details.
π Built with passion by the GraphQL Gateway Team
Scalable β’ Performant β’ Developer-Friendly
K6 benchmark scripts are available under packages/gateway/src/benchmarks
:
Quick commands (run from packages/gateway
):
npm run bench:smoke # baseline latency
npm run bench:ramp # progressive load
npm run bench:mix # read/write mix
npm run bench:spike # burst resilience
npm run bench:soak # long duration stability
Override scale:
RAMP_MAX_VU=1000 npm run bench:ramp
DURATION=1h npm run bench:soak
Set API_KEY
if required for authorization. See src/benchmarks/README.md
for more details.