<p>We have a Spring Boot microservice which should get some data from old / legacy system. This microservice exposes external modern REST API. Sometimes we have to issue 7-10 requests to the legacy system in order to get all the data we need for single API call. Unfortunately we can't use Reactor / <em>WebClient</em> and have to stick with <em><strong>WebServiceTemplate</strong></em> to issue those &quot;legacy&quot; calls. We can't also use <a href="https://stackoverflow.com/questions/49685056/reactive-spring-webclient-making-a-soap-call">Reactive Spring WebClient - Making a SOAP call</a></p>
<p>What is the best way to scale such a miroservice in Kubernetes? We have very big concerns that Thread Pool used for parallel <em><strong>WebServiceTemplate</strong></em> invocation will be depleted very fast, but I'm not sure that creating and exposing custom metric based on active threads count / thread pool size is a good idea.</p>
<p>Any advice will be helpful.</p>

<ol>
<li><p>Enable <a href="https://docs.spring.io/spring-metrics/docs/current/public/prometheus" rel="nofollow noreferrer">Prometheus exporter in Spring</a></p>
</li>
<li><p>Make sure metrics are scraped. You're going to watch for a <code>threadpool_size</code> metric. Refer your k8s/prometheus distro docs to get prometheus service discovery working for you.</p>
</li>
<li><p>Write a horizontal pod autoscaler (HPA) based on a Prometheus metric:</p>
<ul>
<li>Setup <a href="https://github.com/helm/charts/tree/master/stable/prometheus-adapter" rel="nofollow noreferrer">Prometheus-Adapter</a> and follow the HPA walkthrough.</li>
<li>Or follow this guide <a href="https://github.com/stefanprodan/k8s-prom-hpa" rel="nofollow noreferrer">https://github.com/stefanprodan/k8s-prom-hpa</a></li>
</ul>
</li>
</ol>
<p>Depending on what k8s distro you are using, you might have different ways to get the Prometheus and prometheus discovery:</p>
<ul>
<li>(example platform built-in) <a href="https://cloud.google.com/stackdriver/docs/solutions/gke/prometheus" rel="nofollow noreferrer">https://cloud.google.com/stackdriver/docs/solutions/gke/prometheus</a></li>
<li>(example product) <a href="https://docs.datadoghq.com/integrations/prometheus/" rel="nofollow noreferrer">https://docs.datadoghq.com/integrations/prometheus/</a></li>
<li>(example opensource) <a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack" rel="nofollow noreferrer">https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack</a></li>
<li>any other prometheus solution</li>
</ul>
