7

What is the preferred way of serving static files for an application that is deployed in a microservices architecture (in production)?

Let's say for simplicity that I have 3 application servers and one load-balancer that forwards requests to these servers.

  • Should the load-balancer store the files and serve them imminently upon request? OR..
  • Should the load-balancer forward static files requests to the different application instances (each request to a different instance)?

Is there a best practice for this?

Yoaz Menda
  • 1,555
  • 2
  • 21
  • 43
  • 1
    From a CDN. It seems orthogonal to MSs – Constantin Galbenu Dec 22 '17 at 09:20
  • 1
    You need to give a few more details as there are a lot of ways to fo this, and there is no right way. What are these static files, how are they going to be used? What is the usage pattern of your services (peak Read per second, are your users geographically distributed, etc.)? Do you need to control the access to these static files? What are you optimising your efforts for (e.g. scalability, or getting something out quickly for small amount of users, etc.)? – tugberk May 10 '20 at 07:12

2 Answers2

1

As stated in other comments/answers, there are a lot of ways to handle this. This largely depends on what you actually need (version control, access control, http headers, CDN).

Specifically to your question, if it was me, I wouldn't deploy these files on the load balancers, because a newer version of the static files would require a downtime on the load balancers. Instead, I would build very simple Nginx/Caddy containers that their sole purpose is to serve these files, and have the LB route the traffic to those containers.

Birkhoff Lee
  • 788
  • 10
  • 21
0

Best practice would be to store it in a service meant for static content like blob storage (in the cloud this would be Azure Storage, S3, etc.). If necessary, leverage a CDN to improvement latency and throughput to end users.

But as someone else commented, there are many ways to handle this depending on your particular requirements.

dippas
  • 58,591
  • 15
  • 114
  • 126
jpcloud
  • 11
  • 2