API Gateway が共通の入口として全リクエストを受け付け、BFF がフロントエンド固有の関心事を担う二層構成
各 BFF が認証検証・ルーティング・レート制限を個別に実装し、共通処理が重複している
Gateway が横断的関心事、各 BFF がフロントエンド固有の関心事を担う
Gateway のルーティングとレート制限を nginx の設定ファイルで定義する
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;limit_req zone=api_limit burst=5 nodelay;proxy_pass http://bff:3000;
$ cd ch06-gateway-bff$ docker compose up -d$ curl http://localhost:8080/health
API Gateway(nginx)を経由して BFF が 3 つのバックエンド APIを集約する構成
$ curl http://localhost:8080/api/dashboard$ for i in $(seq 1 20); doecho "Request $i: $(curl -s -o /dev/null-w '%{http_code}' http://localhost:8080/api/dashboard)";done
$ 1..20 | ForEach-Object {$code = curl.exe -s -o NUL -w '%{http_code}'http://localhost:8080/api/dashboard;Write-Host "Request ${_}: $code"}