Rate Limiter

TsgcWSRateLimiter — a full-featured rate limiting component that protects server endpoints from excessive traffic, abuse and scraping. Three algorithms, four scopes, long-term quotas and standards-compliant HTTP 429 responses.

TsgcWSRateLimiter

Token-bucket rate limiter. Caps requests per second per client (or per IP) on any WebSocket or HTTP server you attach it to.

Component class

TsgcWSRateLimiter

Protocol

Server-side admission control — attaches to any sgc server.

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Professional / Enterprise

Drop the component, set a few properties, go

Configure rate + burst, hook OnRateLimited, attach to your server.

uses
  sgcWebSocket, sgcWebSocket_Server, sgcRateLimiter;

var
  RL: TsgcWSRateLimiter;
  WSServer: TsgcWebSocketHTTPServer;
begin
  RL := TsgcWSRateLimiter.Create(nil);
  RL.RequestsPerSecond := 20;
  RL.BurstSize         := 50;
  RL.OnRateLimited     := DoRateLimited;

  WSServer := TsgcWebSocketHTTPServer.Create(nil);
  WSServer.Port := 80;
  WSServer.RateLimiter := RL;
  WSServer.Active := True;
end;

What's inside

13 published properties, 12 methods, 3 events — pulled from the component reference.

Diagnostics

Published properties: Stats.

Core

Properties: Enabled.

Algorithms

Properties: TokenBucket, SlidingWindow, FixedWindow.

Scoping

Properties: PerIP, PerAPIKey, PerUser.

Response

Properties: Response.

Persistence

Properties: StorageFile.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Demo Project — 01.WebSocket\09.RateLimiter Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Protect Your Endpoints From Abuse

Download the free trial and rate-limit your sgcWebSockets servers in minutes.