Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java Program for API rate Limiter.Design an API rate limiter which can allows R requests in T seconds. [1st round] --- Solved using

Write a Java Program for API rate Limiter.Design an API rate limiter which can allows R requests in T seconds. [1st round] --- Solved using a map of seconds and counts. For every hit the rateLimit function would check the last T seconds count. Implement a rate limiter based on userId.

READ BEFORE ANSWERING:

The Code should be complete without any errors and should execute.

Incomplete code or code with erros and logical problem will get a downvote.

Imagine we are building an application that is used by many different customers. We want to avoid one customer being able to overload the system by sending too many requests, so we enforce a per-customer rate limit. The rate limit is defined as: Each customer can make X requests per Y seconds

Assuming that customer ID is extracted somehow from the request, implement the following function.

// Perform rate limiting logic for provided customer ID. Return true if the

// request is allowed, and false if it is not.

boolean rateLimit(int customerId)

Follow up :

1] one of our customers have bursty traffic, and are complaining about being rate limited. We want to better accomodate those customers, so we want to adopt a credit based system. It will work as follows:

For each bucket of time, any capacity available below the limit is converted into credits for that customer

There is some maximum number of credits that a customer can accumulate

When a customer exceeds their normal request limit for a window, the credit count starts to decrease. When there are 0 credits, the customer is rate limited.

2] Use the Design principles and design patterns in the code

3] Write Executable code with Junit Tests and Console Tests.

4] How can we use this code in a concurrent environment?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions