# Scaling and resource optimization

UI Bakery consists of [various services](/on-premise/install-and-update/recommendations/architecture-overview.md) that may need to be scaled using different approaches. The default resource specifications outline the minimum requirements for each service, but you might want to adjust these based on your specific solution and usage needs.

All services are stateless (except databases) and can be scaled using either `HorizontalPodAutoscaler` or by setting `replicas` in the deployment specification. However, scaling every service may not be necessary.

The **bakery-gateway**, **bakery-front**, and **workbench-front** services are simple NGINX applications that provide static resource delivery and request routing. These services are resource-efficient and typically do not require scaling.

The **automation, datasource** and **python-runtime** services may need scaling if your solution involves lots of automation runs, datasource requests or Python code executions. Since it is a Node.js app, assigning more than one CPU is not necessary. However, such features heavily rely on memory when handling large datasets. \
\
For the **bakery-back** service, running multiple small replicas might be less efficient than a single instance with more resources. We recommend increasing container CPU and memory resources based on your load.

Check out the example of `HorizontalPodAutoscaler` for the automation service:

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: ui-bakery-automation-hpa
  namespace: ui-bakery
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ui-bakery-automation
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uibakery.io/on-premise/install-and-update/installing-on-premise-version/kubernetes/scaling-and-resource-optimization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
