#402 Caching Forecasts for a High-Load Endpoint

Companies:
Avito
Themes:
System DesignCachingPractice
  • There is an aiWeatherForecast function that calculates the temperature through a neural network in approximately one second.
  • There is a high-load /weather endpoint handling 10k RPS. The endpoint calls getWeatherForecast to obtain the forecast.

Optimize getWeatherForecast for high load:

public class WeatherForecaster {

    public int getWeatherForecast() throws InterruptedException {
        // TODO optimize the method for high load
        return aiWeatherForecast();
    }

    private int aiWeatherForecast() throws InterruptedException {
        Thread.sleep(1000);

        return new Random().nextInt(70) - 30;
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in