Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GateKeeper

This is GateKeeper, a distributed Rate Limiting microservice I built in Go.

I created this pet project to dive deeper into backend engineering, specifically focusing on gRPC, Redis, and writing clean, testable code. The service acts as a guard, checking if incoming requests should be allowed or blocked based on predefined limits.

What's inside?

  • gRPC API: I went with gRPC instead of standard REST for faster, more modern, strongly-typed communication.
  • Two Algorithms:
    • Fixed Window Counter: A simple, memory-efficient approach using basic Redis INCR and EXPIRE.
    • Sliding Window Log: A more advanced approach. I used Redis Sorted Sets (ZSET) and wrote a simple Lua script to ensure everything executes atomically in one go.
  • Clean Architecture: The core business logic is decoupled from the network layer using interfaces and dependency injection.
  • Graceful Shutdown: The server catches OS signals (SIGTERM, SIGINT) to finish processing active requests before shutting down, ensuring connections don't just drop.

Tech Stack

  • Language: Go
  • Database: Redis (with a bit of Lua)
  • API: gRPC & Protocol Buffers
  • Infrastructure: Docker & Docker Compose
  • Testing: miniredis (in-memory Redis mock) and testify

How to Run Locally

You'll need Docker and Docker Compose installed on your machine.

  1. Clone this repository.
  2. Start the app and Redis in the background:
docker compose up --build -d
  1. The gRPC server will start listening on port 50051.

To stop and remove the containers:

docker compose down

Running Tests

I used miniredis so you don't even need a real Redis instance running to execute the tests. Just run:

go test -v ./...

What I'd do differently next time

  • Making sure git is in order before starting coding. This includes correct name and email.

About

Distributed rate limiter with fixed window and sliding window algorithms

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages