title: Building an API Gateway with Dynamic Route Mapping
body: <p>We have multiple services running that serve different parts of our public API. These parts implement the same interface and share the same base path.</p>
  
  <p>I am looking for a good way to implement an API Gateway, or reuse an existing software (e.g. reverse proxy) that can route incoming requests to the respective service, depending on an ID inside the request's path parameter. </p>
  
  <pre><code>/v1/things/{ID}
  
  ID_1 -&gt; route request to internalIP1/v1/things/{ID}
  ID_2 -&gt; route request to internalIP2/v1/things/{ID}
  </code></pre>
  
  <p>Whenever a new "thing" is created in our (fictional) registration-service and a new ID_x is generated, then the routing tables should be updated via an API. Afaik, API Gateways like tyk do not support this use case.</p>
  
  <p>Nginx Plus offers a HTTP API where we could update the mapping dynamically for instance making a simple internal request. Nginx Plus costs money, however.</p>
  
  <p>"Regular" Nginx also allows extensions written in lua which could access these advanced mappings from some kind of data storage, which should probably not http-based itself (speed and overhead), but maybe in-memory like a redis-based shared storage could another alternative.</p>
  
  <p><a href="https://stackoverflow.com/questions/8982717/is-there-any-way-to-configure-nginx-or-other-quick-reverse-proxy-dynamically?rq=1">This related question</a> is four years old by now.</p>