Quick Links:
Introduction:
Hey there, open-source enthusiasts and Go aficionados! I'm back with a quick overview of my open-source project, ThrottleX, a distributed rate limiter for APIs. I'm still pretty new to this open-source world, so your advice is always welcome! ?
ThrottleX is built to help you manage API traffic effectively, keeping your system smooth and fair. Whether it's preventing abuse or handling high load, ThrottleX has you covered. Let's explore some of the rate limiting algorithms that make ThrottleX powerful. ?
ThrottleX comes packed with three core algorithms to help you manage your API traffic:
How It Works: Imagine dividing time into fixed intervals. During each interval, you allow a fixed number of requests — say, 100 requests per minute. Once the window closes, the counter resets.
Use Case: Great for predictable traffic patterns but be wary of the "boundary issue," where many requests near the window's end can bypass the intended rate limit.
How It Works: It's like a moving average — instead of resetting completely at the end of each window, the rate limit "slides" across time, providing smoother control.
Use Case: Perfect for avoiding spikes and distributing requests more evenly.
How It Works: Picture a bucket that fills up with tokens at a steady rate. Requests consume tokens, and if the bucket is empty, requests are blocked until it refills.
Use Case: Ideal for allowing sudden bursts of traffic if tokens are saved up.
Here's a simple example using the Fixed Window rate limiter:
package main import ( "github.com/neelp03/throttlex/ratelimiter" "github.com/neelp03/throttlex/store" "time" "fmt" ) func main() { // Initialize an in-memory store and a Fixed Window rate limiter memStore := store.NewMemoryStore() limiter, err := ratelimiter.NewFixedWindowLimiter(memStore, 10, time.Minute) if err != nil { fmt.Println("Failed to create limiter:", err) return } // Simulate API requests key := "user1" for i := 0; iExpected Output:
Request 1 allowed Request 2 allowed ... (up to 10 allowed) Request 11 blocked Request 12 blocked ... (up to 15 blocked)What's Next for ThrottleX? ?
Stay tuned for these future updates that will make ThrottleX even more powerful!
I'm still new to open source, and I'd love for you to be part of this journey! Contributions are always welcome — whether it's bug fixes, suggestions, or documentation improvements.
Check out the repo: ThrottleX GitHub Repo and give it a star if you find it useful. Feel free to open issues or pull requests — every bit helps!
Final Thoughts
ThrottleX is my attempt to make API rate limiting more accessible and efficient. Let's make it fun (and less of a pain)! ?
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3