Kubernetes cost optimization with Sylius: how to cut your cloud costs
Table of contents
Kubernetes cost optimization with Sylius comes down to three things. First, match PHP-FPM pod resources to actual usage. Second, autoscale only what actually handles traffic. Third, take load off PHP with caching and a CDN so you pay for fewer nodes. In a typical Sylius store, these steps can cut the cluster bill by 20–50% without hurting response times.
Below you'll find a concrete plan, a sample configuration and the trade-offs that tutorials rarely mention. It's all based on how we at Midapt build and maintain Sylius-based stores.
Where the money goes in a Sylius store on Kubernetes
Before you cut anything, break the bill down into its components. In Sylius stores, costs almost always split the same way, although the proportions depend on scale.
- Application compute, i.e. PHP-FPM pods, Nginx and Symfony Messenger workers. Usually 40–60% of the bill.
- Database: managed MySQL or PostgreSQL, often oversized "just in case".
- Supporting services: Redis for sessions and caching, Elasticsearch or OpenSearch if you use advanced search, and a message broker.
- Egress traffic and load balancers. Product images served directly from the cluster are particularly expensive.
- Observability: logs and metrics kept for years with no retention policy.
- Non-production environments: staging and review apps running 24/7, even though they're used for just a few hours a day.
So the first step is visibility. Label resources by environment and component, then collect data on actual CPU and memory usage for 2–4 weeks. Without that, every optimization is guesswork.
Step 1: right-sizing PHP-FPM pods
The most common mistake we see is requests set by gut feeling, e.g. 1 CPU and 2 GiB for a pod that uses a quarter of a core at peak. The scheduler reserves those resources, so you pay for nodes filled with empty reservations.
How to calculate resources for Sylius
- Measure the memory of a single PHP-FPM worker under real traffic. In Sylius this is usually anywhere from several dozen to over a hundred MB, depending on plugins.
- Set pm.max_children so that the number of workers multiplied by worker memory fits within the pod limit with 15–20% headroom.
- Set CPU requests at typical load, not at peak. Autoscaling will handle the peaks.
- Always set a memory limit. It's often better to skip the CPU limit, because PHP throttling can increase response times more than the usage itself would suggest.
Cheaper container startup
Run the Symfony cache warmup and asset compilation at image build time, not when the pod starts. Enable OPcache with preloading. A pod that starts in a few seconds instead of a minute lets you keep a smaller replica buffer, because autoscaling reacts faster.
Rule of thumb: if average utilization of reserved CPU in the cluster drops below 30–40%, you're paying for thin air. Fix your requests before you start negotiating instance prices.
Step 2: HPA autoscaling for traffic and KEDA for queues
Once requests reflect actual usage, you can safely scale horizontally. The Horizontal Pod Autoscaler calculates utilization as a percentage of requests. With inflated values it simply never kicks in, which is why right-sizing has to come first.
PHP-FPM pods
- In production, keep a minimum of 2 replicas for availability. The maximum is set by database capacity, not by budget.
- A CPU utilization target of 60–70% leaves a buffer for sudden traffic spikes.
- A longer stabilization window for scaling down, e.g. 5 minutes, prevents replicas from flapping during campaigns.
- Before known peaks, such as Black Friday or a newsletter send, raise minReplicas in advance. Reactive scaling always lags a little.
Symfony Messenger workers
Workers handling emails, exports or ERP synchronization shouldn't scale on CPU but on queue length. This is where KEDA shines: it can scale down to zero replicas when the queue is empty. For stores with nightly catalog imports, this is one of the quickest wins.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: sylius-php
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: sylius-php
minReplicas: 2
maxReplicas: 12
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 65
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 50
periodSeconds: 60
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: sylius-messenger
spec:
scaleTargetRef:
name: sylius-messenger-worker
minReplicaCount: 0
maxReplicaCount: 8
cooldownPeriod: 300
triggers:
- type: rabbitmq
metadata:
queueName: messages
mode: QueueLength
value: "50"
authenticationRef:
name: rabbitmq-auth
Step 3: caching and CDN, or less PHP per request
The cheapest request is one that never reaches PHP-FPM. In Sylius, a large share of traffic comes from anonymous users browsing categories and product pages, and those pages are very well suited to caching.
- HTTP cache: Varnish or a reverse proxy in front of the application for catalog pages. Split out the cart and session-dependent elements with ESI or load them asynchronously.
- Redis for the Symfony and Doctrine application cache and for sessions. Keeping sessions outside the pod is also a prerequisite for safely using spot nodes.
- Product images: generate LiipImagine thumbnails to object storage and serve them via a CDN. Generating thumbnails on the fly on pods is a classic hidden drain on CPU and bandwidth.
- Static assets: serve them with long cache lifetimes and versioned file names.
A well-configured cache can reduce the number of requests hitting PHP by tens of percent. That translates directly into fewer replicas and fewer nodes.
In a Sylius store, every złoty invested in caching pays for itself many times over in nodes you don't have to run.
Step 4: cheaper nodes, or spot, ARM and better bin packing
It's only worth tackling the machines themselves once the workload is well measured and scales automatically. Before that, cheaper instances just mask the problem.
Spot nodes for stateless pods
PHP-FPM, Nginx and Messenger workers are stateless, so they tolerate interruptions well. Spot instances can be 60–80% cheaper than on-demand. Still, keep a baseline pool on regular nodes, set a PodDisruptionBudget and spread replicas across different instance types and zones.
ARM processors
ARM instances typically offer 15–30% better price-performance for PHP. The prerequisite is multi-arch images and verified PHP extensions and native dependencies.
Bin packing and commitments
Tools such as Karpenter or Cluster Autoscaler size nodes to fit pods and remove empty machines. Cover steady baseline load with reserved instances or 1–3 year savings plans, and leave variable load to autoscaling.
Step 5: database, test environments and observability
The data layer rarely runs inside the cluster itself, but it's often the second-largest item on the bill. Here, savings come mainly from cleaning up, not from buying.
- Database: before you buy a bigger instance, eliminate N+1 queries, add missing indexes and review the slow query log. In Sylius, complex catalog filters and admin panel reports are especially troublesome.
- Search engine: size Elasticsearch or OpenSearch to your catalog. For a few thousand products, a three-node cluster can be overkill.
- Staging and review apps: shut them down outside working hours and set up automatic environment deletion once a pull request is closed. This can cut non-production costs by more than half.
- Logs and metrics: for most data, 7–30 days of retention is enough. Disable debug level in production and sample access logs.
Introduce changes one at a time and compare costs and response times before and after each one. A saving that slows down product page loading usually costs more in lost conversions than it saves on the invoice.
When Kubernetes for Sylius isn't worth it
Not every store needs a cluster. The control plane fee, load balancers, monitoring and, above all, DevOps team time are fixed costs. At small scale, they outweigh the benefits. A cluster usually doesn't pay off when:
- traffic is stable and fits on 1–3 servers,
- you don't have someone who understands Kubernetes and owns the cluster,
- you deploy changes less often than once every few weeks.
In these cases, a managed platform or a few well-configured virtual machines will be cheaper and simpler. Kubernetes starts paying for itself with pronounced traffic peaks and multiple environments. It also makes sense with several stores or sales channels and a team that deploys changes regularly. We help you make this decision as part of our Cloud & DevOps services.
Kubernetes cost optimization with Sylius: where to start
Kubernetes cost optimization with Sylius is a process, not a one-off exercise. Order matters. Start with cost visibility and right-sizing, then autoscaling, caching and CDN, and finally cheaper nodes and commitments. Reversing this order usually ends with cheap machines full of empty reservations.
If your cloud bill is growing faster than your sales, book a free consultation. We'll review your cluster and store configuration, pinpoint the biggest sources of waste and estimate realistic savings. See also how we support companies in the e-commerce industry.
FAQ: Kubernetes costs for Sylius stores
Yes. Sylius is built on Symfony, and its application layer is stateless as long as you move sessions and cache to Redis and files to object storage. Then PHP-FPM pods can be freely scaled and moved between nodes. The prerequisite is a well-prepared image with a warmed-up Symfony cache and OPcache, plus separate deployments for Messenger workers.
In a typical store that hasn't been optimized before, realistic savings are usually 20–50% of the cluster bill. The biggest impact comes from fixing inflated requests, autoscaling, caching and CDN, and shutting down test environments outside working hours. Spot nodes and reserved instances add a few more percent, but only once the basics are in order.
Yes, as long as you only run stateless components on them: PHP-FPM, Nginx and queue workers. Sessions must live in Redis, not in the pod. Keep a baseline pool of on-demand nodes, set a PodDisruptionBudget and use several instance types. Don't run the database, message broker or search engine on spot without replication.
Ideally both, each for a different job. HPA works well for PHP-FPM pods handling HTTP traffic, scaling them based on CPU utilization. KEDA is a better fit for Symfony Messenger workers, because it scales them based on queue length and can scale down to zero replicas when there are no jobs to process.
It depends on traffic, the number of environments and supporting services. A small production cluster with a managed database, Redis and staging typically costs from a few hundred to a few thousand złoty (PLN) per month for infrastructure alone. On top of that comes DevOps team time, which at small scale can cost more than the cloud itself.



