R2 Gateway: Cost-Controlled S3-Compatible Object Storage Gateway


DEMO:https://s3.fujisaki.top/public/blog/demo.html

GITHUB

Overview
R2 Gateway is a lightweight object storage gateway built on top of S3-compatible services such as Cloudflare R2. The system focuses on cost safety, introducing a control mechanism that automatically disables access once usage exceeds a predefined threshold, preventing unexpected billing.


Key Features

  • Cost Limit Enforcement (Core Feature)
    • Monitors storage or traffic usage
    • Automatically blocks requests when exceeding configured limits
    • Prevents uncontrolled cost growth in pay-as-you-go environments
  • S3-Compatible API Layer
    Supports standard object storage operations (upload, download, list), enabling seamless integration with existing tools
  • Gateway-Based Control Layer
    All requests pass through the gateway, allowing:
    • Centralized quota enforcement
    • Request filtering / rejection
    • Unified access management
  • Direct HTTP File Serving
    Provides URL-based access to stored objects for static assets (e.g., PDFs, images)

Technical Highlights

  • Quota-Aware Request Interception
    Each incoming request is checked against usage limits before being forwarded, ensuring strict cost control
  • Fail-Fast Mechanism
    Requests are immediately rejected once thresholds are exceeded, avoiding unnecessary backend operations
  • Lightweight Deployment
    Designed for self-hosted environments (VPS), with Docker-based deployment support
  • Extensible Storage Abstraction
    Compatible with any S3-like backend beyond Cloudflare R2

Use Cases

  • Personal projects requiring strict budget control
  • Preventing unexpected cloud storage bills
  • Self-hosted file services with usage limits
  • Static asset hosting with safety constraints