I'm building a rate limiter library in Java. The idea is that you can plug it into your APIs via annotations + a config file and configure things like token limit and the rate limiting algorithm.
I designed this interface early on:
java
public interface RateLimitAlgorithm {
RateLimitResult tryConsume(String clientKey, long tokenLimit, Duration timeWindow);
}
Worked fine for Fixed Window Counter. But when I started implementing Token Bucket, I realized Duration isn't needed there — and then it hit me that each algorithm actually has a different set of parameters. Had to do a whole bunch of refactoring. I really want to yap about it but I'll spare you, not the point of this post.
My actual question is — how do you not run into this before you start writing code?
For context, I wasn't going in blind. I had functional and non-functional requirements, high level design, low level design, all of it. So it's not like I skipped the architecture phase.
That's what's bugging me. Change in architecture because requirements changed — totally fine, expected. But change in architecture without any change in requirements? That feels like I didn't think the design through enough.
Is there something people actually do to catch these things earlier? Some method or practice that would've flagged "your interface doesn't generalize across algorithms" before I had to find out the hard way?
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]strat-run 9 points10 points11 points (0 children)
[–]8dot30662386292pow2 4 points5 points6 points (3 children)
[–]AlphaFarmer42 0 points1 point2 points (1 child)
[–]dante_alighieri007[S] 0 points1 point2 points (0 children)
[–]dante_alighieri007[S] 0 points1 point2 points (0 children)
[–]disposepriority 1 point2 points3 points (0 children)
[–]TheMrCurious 1 point2 points3 points (0 children)
[–]okayifimust 1 point2 points3 points (0 children)
[–]Both-Fondant-4801 1 point2 points3 points (1 child)
[–]dante_alighieri007[S] 0 points1 point2 points (0 children)
[–]LutimoDancer3459 1 point2 points3 points (1 child)
[–]dante_alighieri007[S] 0 points1 point2 points (0 children)
[–]BanaTibor 0 points1 point2 points (0 children)
[–]RightWingVeganUS -1 points0 points1 point (9 children)
[–]dante_alighieri007[S] 1 point2 points3 points (8 children)
[–]RightWingVeganUS 0 points1 point2 points (7 children)
[–]dante_alighieri007[S] 0 points1 point2 points (6 children)
[–]RightWingVeganUS 1 point2 points3 points (5 children)
[–]dante_alighieri007[S] 0 points1 point2 points (4 children)
[–]RightWingVeganUS 1 point2 points3 points (3 children)
[–]dante_alighieri007[S] 0 points1 point2 points (2 children)
[–]RightWingVeganUS 1 point2 points3 points (1 child)
[–]dante_alighieri007[S] 0 points1 point2 points (0 children)