Backend Engineer: Distributed API Gateways & Redis Lua Rate Limiting

Protect high-throughput APIs and AI token budgets by hiring freelance Golang programmer Aldian Fazrihady to build atomic Redis Lua token-bucket rate limiters. With 15+ years of full-stack software engineering experience, Aldian Fazrihady partners directly with CTOs, VPs of Engineering, and technical founders via Upwork and direct B2B consulting contracts.

1. Production Architecture: Distributed Atomic Token-Bucket Rate Limiting in Go 1.23 with Redis Lua Scripts

Hiring a senior freelance programmer requires verifiable production patterns rather than generic boilerplate. Below is a battle-tested implementation pattern used in high-availability systems:

package ratelimit

import (
	"context"
	"time"
	"github.com/redis/go-redis/v9"
)

var tokenBucketLua = redis.NewScript(`
local key = KEYS[1]
local capacity = tonumber(ARGV[1])
local refill_rate = tonumber(ARGV[2])
local now_ms = tonumber(ARGV[3])
local requested = tonumber(ARGV[4])

local data = redis.call("HMGET", key, "tokens", "last_ms")
local tokens = tonumber(data[1])
local last_ms = tonumber(data[2])

if tokens == nil then
  tokens = capacity
  last_ms = now_ms
else
  local elapsed = math.max(0, now_ms - last_ms)
  tokens = math.min(capacity, tokens + (elapsed * refill_rate / 1000.0))
  last_ms = now_ms
end

if tokens >= requested then
  tokens = tokens - requested
  redis.call("HMSET", key, "tokens", tokens, "last_ms", last_ms)
  redis.call("PEXPIRE", key, 3600000)
  return 1
end
return 0
`)

func AllowRequest(ctx context.Context, rdb *redis.Client, tenantKey string, capacity, ratePerSec, cost int) (bool, error) {
	res, err := tokenBucketLua.Run(ctx, rdb, []string{tenantKey}, capacity, ratePerSec, time.Now().UnixMilli(), cost).Int()
	return res == 1, err
}

2. Key Engineering Guarantees

  • Single-Roundtrip Atomic Execution: Running token-bucket math inside a compiled Redis Lua script to eliminate race conditions across hundreds of Go API gateway pods.
  • Tenant-Tiered AI Token Quotas: Enforcing both requests-per-second (RPS) and LLM tokens-per-minute (TPM) budgets per enterprise tenant.
  • Sub-Millisecond Overhead: Keeping p99 gateway middleware latency under 0.8ms at 25,000+ concurrent requests per second.

3. Explore the 5 Topical Category Hubs & Master Directory

4. Frequently Asked Questions (FAQ)

How quickly can Aldian Fazrihady onboard into our repository?

Within 24 to 48 hours, shipping production pull requests with automated test coverage in the first week.

Can we hire Aldian via Upwork or direct B2B invoicing?

Yes. You can initiate an escrow contract on Upwork or engage via direct B2B retainer and milestone invoicing.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs