AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Api Gateway Patterns

skill-camilooscargbaptista-cto-toolkit-api-gateway-patterns · by camilooscargbaptista

API Gateway design patterns including rate limiting, authentication, versioning, BFF and circuit breaking

No reviews yet
0 installs
16 views
0.0% view→install

Install

$ agentstack add skill-camilooscargbaptista-cto-toolkit-api-gateway-patterns

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access Used
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-camilooscargbaptista-cto-toolkit-api-gateway-patterns)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
4mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Api Gateway Patterns? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

API Gateway Patterns

When to Use

  • Designing an API gateway for microservices
  • Implementing rate limiting, authentication, or request routing
  • Evaluating BFF (Backend for Frontend) pattern
  • Adding circuit breaking to external service calls

Gateway Architecture

                    ┌─────────────────────┐
                    │    API Gateway       │
                    │                     │
  Clients ────────►│  1. Rate Limiting    │
                    │  2. Authentication   │
                    │  3. Request Routing  │
                    │  4. Load Balancing   │
                    │  5. Circuit Breaking │
                    │  6. Response Caching │
                    │  7. Logging/Tracing  │
                    └────┬────┬────┬──────┘
                         │    │    │
                    ┌────┘    │    └────┐
                    ▼         ▼         ▼
              ┌──────┐  ┌──────┐  ┌──────┐
              │Svc A │  │Svc B │  │Svc C │
              └──────┘  └──────┘  └──────┘

Rate Limiting Patterns

Token Bucket (recommended)

// Allows burst then throttles
const rateLimiter = {
  bucketSize: 100,      // Max tokens
  refillRate: 10,       // Tokens per second
  refillInterval: 1000, // ms
};
// Burst: 100 requests instantly, then 10/sec sustained

Sliding Window

// More accurate, no burst
// Count requests in last N seconds
// Redis implementation:
// ZADD rate:{userId} {timestamp} {requestId}
// ZREMRANGEBYSCORE rate:{userId} 0 {timestamp - window}
// ZCARD rate:{userId}

Rate Limit by Tier

| Tier | Rate Limit | Burst | |------|-----------|-------| | Free | 100 req/hour | 10 req/sec | | Basic | 1000 req/hour | 50 req/sec | | Pro | 10000 req/hour | 200 req/sec | | Enterprise | Custom | Custom |

Response Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1619472000
Retry-After: 60

API Versioning Strategies

| Strategy | Example | Pros | Cons | |----------|---------|------|------| | URL path | /v1/users | Simple, clear | URL pollution | | Header | Accept: application/vnd.api.v1+json | Clean URLs | Hidden, harder to test | | Query param | /users?version=1 | Easy to switch | Messy |

Recommendation: URL path for public APIs, header for internal APIs.

Deprecation Policy

v1: Active → Deprecated → Sunset
    │          │           │
    └──────────┘           │
      6 months minimum     │
      communication        │
                           └── Remove with 3-month warning

BFF (Backend for Frontend)

┌────────┐     ┌─────────────┐     ┌──────────┐
│ Mobile  │────►│ Mobile BFF  │────►│          │
│ App     │     │ (optimized) │     │          │
└────────┘     └─────────────┘     │  Core    │
                                    │  Services │
┌────────┐     ┌─────────────┐     │          │
│ Web    │────►│  Web BFF    │────►│          │
│ App     │     │ (full data) │     │          │
└────────┘     └─────────────┘     └──────────┘

Mobile BFF: Less data, compressed images, offline-first
Web BFF:    Full data, SSR support, WebSocket

Circuit Breaker

enum CircuitState { CLOSED, OPEN, HALF_OPEN }

class CircuitBreaker {
  private state = CircuitState.CLOSED;
  private failureCount = 0;
  private successCount = 0;
  private lastFailureTime: Date;

  private readonly threshold = 5;        // Failures to open
  private readonly timeout = 30000;      // ms before half-open
  private readonly halfOpenMax = 3;      // Successes to close

  async execute(fn: () => Promise): Promise {
    if (this.state === CircuitState.OPEN) {
      if (Date.now() - this.lastFailureTime.getTime() > this.timeout) {
        this.state = CircuitState.HALF_OPEN;
      } else {
        throw new Error('Circuit is OPEN — service unavailable');
      }
    }

    try {
      const result = await fn();
      this.onSuccess();
      return result;
    } catch (error) {
      this.onFailure();
      throw error;
    }
  }

  private onSuccess() {
    if (this.state === CircuitState.HALF_OPEN) {
      this.successCount++;
      if (this.successCount >= this.halfOpenMax) {
        this.state = CircuitState.CLOSED;
        this.failureCount = 0;
      }
    }
    this.failureCount = 0;
  }

  private onFailure() {
    this.failureCount++;
    this.lastFailureTime = new Date();
    if (this.failureCount >= this.threshold) {
      this.state = CircuitState.OPEN;
    }
  }
}

Request/Response Transformation

// Gateway aggregation — single client call, multiple services
@Get('dashboard')
async getDashboard(@User() user) {
  const [profile, stats, notifications] = await Promise.allSettled([
    this.userService.getProfile(user.id),
    this.billingService.getStats(user.companyId),
    this.notificationService.getUnread(user.id),
  ]);

  return {
    profile: profile.status === 'fulfilled' ? profile.value : null,
    stats: stats.status === 'fulfilled' ? stats.value : null,
    notifications: notifications.status === 'fulfilled' ? notifications.value : [],
  };
  // Graceful degradation: partial response even if one service fails
}

Quality Gates

  • [ ] Rate limiting configured on all public endpoints
  • [ ] Authentication at gateway level (not duplicated in services)
  • [ ] API versioning strategy defined and documented
  • [ ] Circuit breakers on all external service calls
  • [ ] Request/response logging with correlation IDs
  • [ ] Health check endpoint for each downstream service
  • [ ] Timeout configured for all downstream calls

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.