title: Advice with the deployment strategy to follow with NextJS
body: <p>Could you recommend us the best practices to deploy applications in production with nextjs?</p>
  
  <p>We are thinking in strategies like: canary deployment, blue/green deployment... We have several doubts to handle BUILD_ID.</p>
  
  <p>Right now, with this kind of strategies we are facing with this error: </p>
  
  <blockquote>
    <p>INVALID_BUILD_ID, because in some moment of the deployment we have at
    least two different versions of the application.</p>
  </blockquote>
  
  <p>for example:</p>
  
  <p>On a Canary deployment, at one point we have 2 different versions, The balancer send a client to
  version A, but then when the client need other resources, the balancer could send this request to a
  server with version B. At this point the client receive a 500 error when the app fetches resources like serp.js, _error.js, _document.js, and the webpage is not loaded correctly.</p>
  
  <pre><code>_next/f6bff019-9550-4029-99fa-2b33a50045f6/page/index.js ---&gt; old (previous deployment)
  
  _next/005b2202-c5b2-4de6-afd8-1c8451d16ab3/page/index.js ---&gt; new (current deployment)
  </code></pre>
  
  <p>Until now, we have tested:</p>
  
  <ol>
  <li><p>Rename the BUILD_ID to have the same hash in both versions, but we think is a bad practice, because we think that the client's cache will not be refreshed how is expected.</p></li>
  <li><p>Sticky sessions are the most reliable, but we handle a stateless app as an app with the state, and really is not true.</p></li>
  <li><p>We could put on front a CDN that caches the BUILD_ID, but we are not sure that the time we should assign for the cache of the js files.</p></li>
  </ol>