gatewise

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT

README

Gatewise

HTTP admission control for Go applications and HTTP backends. Gatewise bounds concurrent requests, reserves capacity for critical traffic, and optionally adjusts admission using latency and error feedback.

Use it as Go middleware or as a standalone proxy in front of an HTTP service written in any language.

Documentation · Installation · Examples · Benchmarks

Go middleware

Requires Go 1.22 or newer.

go get github.com/HN026/gatewise@v0.1.0
import "github.com/HN026/gatewise/middleware"

// Example values: choose limits by load testing your service.
guard, err := middleware.NewService(middleware.ServiceConfig{
    Name: "orders", MaxConcurrent: 20, ReservedCritical: 5,
})
if err != nil {
    log.Fatal(err)
}
mux.Handle("POST /checkout", guard.Middleware(
    middleware.Critical, http.HandlerFunc(checkout),
))
mux.Handle("POST /reindex", guard.Middleware(
    middleware.Background, http.HandlerFunc(reindex),
))

This is an integration fragment: mux is your http.ServeMux and checkout/reindex are application handlers. See the complete example.

The example allows 20 requests running simultaneously across both routes, with background work limited to 15. This is concurrency, not requests per second. Reuse one guard for routes sharing capacity. Excess requests receive structured HTTP 503 responses. Limits are configurable and apply per process.

Standalone proxy

git clone --branch v0.1.0 https://github.com/HN026/gatewise.git
cd gatewise
go build -o bin/gatewise ./cmd/gatewise

Save a configuration such as configs/orders.json:

{
  "listen_addr": "127.0.0.1:8080",
  "services": {
    "orders": {
      "upstream_url": "http://127.0.0.1:9090",
      "max_concurrent": 20,
      "reserved_critical": 5
    }
  },
  "routes": [
    {"path_prefix": "/orders", "service": "orders", "strip_prefix": true, "priority": "critical"},
    {"path_prefix": "/orders/background", "service": "orders", "strip_prefix": true, "priority": "background"}
  ]
}

Addresses and limits above are examples. Point upstream_url at your running backend, then start:

./bin/gatewise -config configs/orders.json -env-file ""
curl -i http://127.0.0.1:8080/healthz
curl -i http://127.0.0.1:8080/orders/hello

The second request forwards /hello to your backend; its response depends on that handler. Routing uses the longest matching path-segment prefix. Configuration precedence is process environment > dotenv > JSON > defaults. Configuration is resolved at startup. See the reference for adaptive settings, route budgets and environment variables.

Metrics and operations

The proxy exposes /healthz and Prometheus /metrics outside admission. Go applications can register a guard using metrics.Register with their own Prometheus registry. A Grafana dashboard and optional local monitoring stack are included under deploy/observability/.

Slots are held until synchronous handlers return. There is no admission queue or preemption. Adaptive mode uses completed-request feedback within configured bounds; it does not directly measure database capacity. Multiple replicas have independent budgets. Applications own retry policy, dependency timeouts, authentication and TLS. Long-lived streaming and WebSocket support are outside the current scope.

Demo example and measurements

The separate documentation repository contains independent demo backends, a middleware consumer, a synthetic benchmark fixture and Postman requests. Download and run the demo example.

Published charts describe controlled local experiments, not production capacity guarantees. Rejected requests and successful-request latency are reported separately. The benchmark runner is in benchmarks/; the fixture is supplied in the demo example.

Development

go test -race ./...
go vet ./...
go build ./cmd/gatewise

Public packages are middleware/ and metrics/. Executable wiring is in cmd/; implementation packages are in internal/; focused tests are under tests/.

License

MIT. Gatewise is an independent project inspired by published overload-control techniques; it is not affiliated with Uber.

Directories

Path Synopsis
cmd
gatewise command
gatewise-bench command
gatewise-bench runs local, isolated M6 overload experiments.
gatewise-bench runs local, isolated M6 overload experiments.
internal
adaptive
Package adaptive implements bounded, request-driven feedback control.
Package adaptive implements bounded, request-driven feedback control.
admission
Package admission provides process-local concurrency admission without a waiting queue.
Package admission provides process-local concurrency admission without a waiting queue.
benchmark
Package benchmark implements bounded local M6 experiments.
Package benchmark implements bounded local M6 experiments.
Package metrics exports Gatewise service statistics to a caller-owned Prometheus registry.
Package metrics exports Gatewise service statistics to a caller-owned Prometheus registry.
Package middleware provides HTTP admission control for Go services.
Package middleware provides HTTP admission control for Go services.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL