Thomson Ignesious
Thomson Ignesious

Reputation: 715

Interview question: How do you scale or optimize a microservice which receives millions of requests?

I was asked a question during an interview: How do you optimize a microservice which receives millions of requests? How do you optimize the latency/frequency of a service response which accessed multiple times?

My answer was: I would check the DB query which makes the response slow and then configure the cache.

Can anyone let me in what are the ways a service can be optimized other than these? if there is anything cloud side?

Upvotes: 0

Views: 531

Answers (2)

Cosmin Ioniță
Cosmin Ioniță

Reputation: 4045

Here are my ideas on this question:

  • Caching, as you mentioned, is a good optimization point when around the data access layer. I would check to see if there is any opportunity to add a cache without breaking the consistency or other hard requirements there may be for the application.
  • I would analyze the CPU and memory usage and adjust them progressively while monitoring the latency closely. The objective here is to find the point when more resources does not decrease the latency significantly.
  • The above point has to consider the adjustment of the number of threads in the application, and also making sure that you optimize the synchronization scheme.
  • If the microservice is built in a JVM-based language, the GC is one component that may introduce latency, mostly when it kicks in, so if the latency spikes correlates with GC cycles, then I would search for optimizations there.
  • Making sure the application is reusing connections to external services efficiently is another optimization point that may be considered

Upvotes: 1

Mannekenpix
Mannekenpix

Reputation: 752

It is a vast and complex questions which can have a lot of different (and very long) answers based on the context and the structure of your environment.

There are a lot of patterns and concepts which fit different scenario and architecture.

I would suggest you to start here: https://microservices.io/patterns/index.html

The guy behind the site (Chris Richardson) advocates microservices since a long time. You can find numerous talks of this guy on Youtube. It is a great way to start your journey in the microservice world.

And off course: https://martinfowler.com/articles/microservices.html

Upvotes: 2

Related Questions