Most shops that say they run "in the cloud" are a classic PHP application on a rented virtual machine. That saves buying hardware, but the shop still writes files to its local disk, keeps sessions in memory and needs a bigger machine when traffic grows. If that machine fails, the shop is offline.

A cloud-native shop is built so that servers can come and go. It scales by adding instances, recovers from failures on its own and is deployed through automated pipelines. This post explains which design decisions make that possible, shows what they look like in a Laravel shop using the open source Aimeos e-commerce framework, and ends with a checklist you can use to test any platform.

Cloud-hosted compared to cloud-native

The Cloud Native Computing Foundation describes cloud-native technologies as those that let organizations build and run scalable applications in dynamic environments such as public, private and hybrid clouds. In practice the label is about how an application behaves when the environment around it changes.

Aspect Cloud-hosted Cloud-native
Scaling Bigger server (vertical) More instances (horizontal)
Files and media Local disk Object storage such as S3
Sessions and cache Server memory Shared store such as Redis
Deployment Manual, often with downtime Automated pipeline, rolling updates
Server failure Shop goes offline Instance is replaced automatically
Infrastructure Configured by hand Defined as code

The building blocks

Each of the following design decisions removes one reason why the shop could not simply run on more machines.

Architecture of a cloud-native shop: customers reach a CDN and load balancer, which forwards requests to several identical, stateless app instances. A CI/CD pipeline rolls out new images to them. All instances share a database, a cache, object storage, a search engine and a message queue, which feeds background workers.

Principle What it means for a shop
Stateless servers Web servers keep nothing that must survive the next request. Sessions, baskets, caches and files live in shared services, so a load balancer can send any request to any instance.
Horizontal scaling Capacity grows by starting more identical instances. A shop that needs four instances on a normal weekday could run forty during a Black Friday sale.
Containers The application ships as one image that runs the same on a laptop, in staging and in production. Kubernetes or a managed platform starts it, checks its health and replaces failed instances.
Managed backing services Database, cache, search, queue and mail are services found through environment variables, as described by The Twelve-Factor App.
Background processing Mails, imports, exports and index updates run in worker containers that scale independently from the storefront.
APIs first The backend offers its functions through REST, JSON:API or GraphQL, so websites, apps and marketplace connectors can use the same backend.
Automation and observability Infrastructure is defined as code, a pipeline rolls out new versions instance by instance, and logs and metrics are collected centrally.

In practice: a Laravel shop with Aimeos

I work on Aimeos, so the examples use it. The following steps show how the principles above map to a Laravel application with Aimeos, and Aimeos for Symfony and TYPO3 uses the same resource keys. All config/shop.php snippets are parts of the one array that this file returns, so merge them into your existing configuration.

1. Build one container image

Web and worker containers use the same image. This one builds on the serversideup/php FrankenPHP image, which already contains Composer and the common database and Redis extensions:

FROM serversideup/php:8.5-frankenphp USER root RUN install-php-extensions intl gd USER www-data # OPcache is disabled in the serversideup images by default ENV PHP_OPCACHE_ENABLE=1 # dependencies first, so this layer is reused when only the code changes COPY --chown=www-data:www-data composer.json composer.lock /var/www/html/ RUN composer install --no-dev --no-scripts --no-autoloader --no-interaction COPY --chown=www-data:www-data . /var/www/html RUN composer install --no-dev --optimize-autoloader --no-interaction \ && php artisan vendor:publish --tag=public --force 

The last command copies the CSS, JS and images of the Aimeos packages to public/vendor. Composer only runs it after composer update, so without it the image contains a shop without styles.

Add a .dockerignore so local files don't end up in the image:

.env .git node_modules vendor storage/logs/* 

Laravel caches its configuration, routes and views with php artisan optimize. Run it when the container starts and not during docker build, because the cached configuration contains the environment values of the moment it was created. The serversideup images can do this for you, but the same switch also runs migrate --force in every starting container, which conflicts with step 7. Enable the start tasks and turn off the migration in the environment of the container, like in the deployment in step 9. The entrypoint reads them before Laravel starts, so they have no effect in .env:

AUTORUN_ENABLED=true AUTORUN_LARAVEL_MIGRATION=false 

Applications based on the Laravel 11+ skeleton include a /up route that returns HTTP 200 when the application boots. It doesn't check whether the database or Redis can be reached, which makes it a good liveness probe. If the readiness probe should also cover the backing services, add your own route that tests the connections.

The Aimeos distribution (composer create-project aimeos/aimeos) still uses the older Laravel structure without this route. Add it in the routes() callback of app/Providers/RouteServiceProvider.php, outside of the web middleware group, so the probes don't create a new session every few seconds:

Route::get('/up', fn () => response('OK')); 

2. Make all pods equal behind the load balancer

All instances must use the same APP_KEY. Laravel encrypts its cookies with it, and if one pod generated its own key, the requests it receives can't decrypt the cookies set by the other pods. Customers then lose their basket or login at random, which is hard to trace back. Pass the key as a secret to every container and never run php artisan key:generate in the image.

The load balancer terminates HTTPS and forwards plain HTTP to the pods. Unless Laravel trusts the proxy headers, it generates http:// URLs and sees the balancer's IP as the client address. That breaks payment redirects and callback URLs. The Aimeos distribution trusts the private network ranges by default (TRUSTED_PROXIES in config/app.php), which covers most cluster load balancers. In an application based on the Laravel 11+ skeleton, add this to bootstrap/app.php:

use Illuminate\Http\Request; // ... ->withMiddleware(function (Middleware $middleware) { $middleware->trustProxies( at: ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'], // network of your load balancer headers: Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO, ); }) 

Avoid at: '*' and leave out X-Forwarded-Host. Many load balancers pass that header unchanged from the client, and Laravel uses it to generate URLs, for example the links in password reset e-mails.

3. Move sessions and cache to Redis

Aimeos stores the basket in the Laravel session, so sessions must be shared before you can run several instances without sticky sessions. In .env:

SESSION_DRIVER=redis CACHE_STORE=redis REDIS_HOST=redis.internal 

Aimeos also caches rendered HTML parts and keeps that cache in the database by default. The ai-cache extension moves it to Redis:

composer req aimeos/ai-cache 
// config/shop.php 'resource' => [ 'cache' => [ 'redis' => [ 'connection' => [ 'scheme' => 'tcp', 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => 6379, 'database' => 2, ], ], ], ], 'madmin' => [ 'cache' => [ 'manager' => [ 'name' => 'Redis', ], ], ], 

The connection settings must be inside connection, because the extension passes all other keys as options to the Predis client. Placed directly under redis, they are ignored and Aimeos connects to 127.0.0.1 instead.

Give the Aimeos cache a Redis database of its own. Clearing it, for example with php artisan aimeos:clear after a deployment, runs FLUSHDB on that database. Laravel stores sessions in database 0 by default, so a shared database would log out all customers and empty their baskets.

4. Move all shop files to object storage

Aimeos uses several file system resources, and all of them must be shared once more than one container runs:

Resource Content Written by Read by
fs-media Product images and files Admin Customers via CDN
fs-import Uploaded CSV and XML imports Admin (web) Import jobs (worker)
fs-export Product exports and delivery XML files Jobs (worker) Marketplaces, ERP and other external systems
fs-secure Files of downloadable products Admin Customer account (web)
fs-admin Order and subscription CSV exports, log archives Jobs (worker) Admin dashboard (web)

If fs-import stays on the local disk, a CSV uploaded through one web container is never seen by the worker that should import it. The ai-filesystem extension provides Flysystem adapters for S3 and other object stores:

composer req aimeos/ai-filesystem league/flysystem-aws-s3-v3 
// config/shop.php $s3 = fn( string $prefix ) => [ 'adapter' => 'FlyAwsS3', 'credentials' => [ 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), ], 'region' => env('AWS_DEFAULT_REGION'), 'version' => 'latest', 'bucket' => env('AWS_BUCKET'), 'prefix' => $prefix, 'tempdir' => storage_path('tmp'), ]; return [ 'resource' => [ 'fs-media' => $s3('media') + ['baseurl' => env('AWS_URL') . '/media'], 'fs-import' => $s3('import'), 'fs-export' => $s3('export'), 'fs-secure' => $s3('secure'), 'fs-admin' => $s3('admin'), // ... ], // ... ]; 

Only the media prefix may be publicly readable. Imports, exports, admin files and secure downloads contain customer and order data, so restrict them through the bucket policy or use a second, private bucket. Point AWS_URL to a CDN in front of the bucket so images are delivered without touching your application servers. Theme files and MIME icons ship with the container image and can stay local.

5. Keep product search in the shared database

Aimeos stores its search data in index tables of the database and updates them when products are saved or imported. All pods query the same tables, so search needs nothing else to be shared and no additional service to operate. The daily index/optimize job in the next step keeps these tables fast.

For catalogs with millions of products or very high search traffic, Aimeos offers a commercial Elasticsearch extension that moves the search queries out of the database. If you use it, include the scheme in the host setting (https://...), because the Elasticsearch client defaults to plain HTTP while Elasticsearch 8 only accepts HTTPS.

6. Run jobs in a worker container

Aimeos runs e-mails, imports, exports and index maintenance as job controllers through php artisan aimeos:jobs. With the Laravel scheduler in routes/console.php:

use Illuminate\Support\Facades\Schedule; Schedule::command('aimeos:jobs "order/email/payment order/email/delivery order/service/delivery"') ->everyFiveMinutes() ->onOneServer(); Schedule::command('aimeos:jobs "product/import/csv"') ->everyFiveMinutes() ->withoutOverlapping(60) ->onOneServer(); Schedule::command('aimeos:jobs "index/optimize"') ->dailyAt('01:00') ->onOneServer(); 

Start the same image with php artisan schedule:work as the worker container:

apiVersion: apps/v1 kind: Deployment metadata: name: shop-worker spec: replicas: 1 selector: matchLabels: app: shop-worker template: metadata: labels: app: shop-worker spec: terminationGracePeriodSeconds: 120 containers: - name: worker image: registry.example.com/shop:1.0.0 command: ["php", "artisan", "schedule:work"] envFrom: - configMapRef: name: shop-env - secretRef: name: shop-secrets resources: requests: cpu: 250m memory: 512Mi limits: memory: 1Gi 

The shop-env ConfigMap contains the settings from your .env file, and the shop-secrets Secret contains APP_KEY, the database password and the S3 credentials. The grace period gives a running job two minutes to finish when Kubernetes stops the pod.

onOneServer() takes a lock in the shared Redis cache, so each job runs once even if several workers are running. withoutOverlapping(60) keeps a large import from starting a second time while the first one is still running, and CSV files uploaded in the admin are imported within a few minutes. The 60 minutes limit how long the lock is held. Without it, the lock expires only after 24 hours, and if Kubernetes stops the worker pod during an import, no further imports run until the next day.

Internally, Aimeos uses a message queue resource (mq) that is stored in the database by default. If you need a dedicated broker, the ai-mqueue extension adds AMQP (RabbitMQ), Beanstalk and Stomp adapters.

7. Update the database during deployment

Run the schema updates once per release, before the new containers start. In Kubernetes this is a Job that the pipeline starts before it rolls out the new image, never part of the web container start:

apiVersion: batch/v1 kind: Job metadata: name: shop-migrate-1-0-0 # job names are unique, so include the release version spec: backoffLimit: 1 ttlSecondsAfterFinished: 86400 template: spec: restartPolicy: Never containers: - name: migrate image: registry.example.com/shop:1.0.0 command: ["sh", "-c", "php artisan migrate --force && php artisan aimeos:setup"] envFrom: - configMapRef: name: shop-env - secretRef: name: shop-secrets 

During a rolling update, old and new containers run at the same time. Keep your own schema changes backward compatible: add columns first, and remove old ones only in a later release.

8. Send logs to stdout

Container platforms collect what an application writes to stdout and stderr. For Laravel, set this in .env:

LOG_CHANNEL=stderr 

Aimeos writes its own log entries to the madmin_log table in the shared database, so they are already central and visible in the admin interface. If you want them in the same log pipeline as Laravel, the ai-monolog extension passes them to a Monolog logger.

9. Scale the web containers

The web containers run as a deployment of the same image. It sets the start tasks from step 1, the probes on /up and the CPU request that the autoscaler needs, and it spreads the pods across availability zones so three replicas don't share a single point of failure:

apiVersion: apps/v1 kind: Deployment metadata: name: shop-web spec: replicas: 3 selector: matchLabels: app: shop-web strategy: rollingUpdate: maxUnavailable: 0 maxSurge: 1 template: metadata: labels: app: shop-web spec: topologySpreadConstraints: - maxSkew: 1 topologyKey: topology.kubernetes.io/zone whenUnsatisfiable: ScheduleAnyway labelSelector: matchLabels: app: shop-web containers: - name: web image: registry.example.com/shop:1.0.0 ports: - containerPort: 8080 env: - name: AUTORUN_ENABLED value: "true" - name: AUTORUN_LARAVEL_MIGRATION value: "false" envFrom: - configMapRef: name: shop-env - secretRef: name: shop-secrets resources: requests: cpu: 500m memory: 512Mi limits: memory: 1Gi readinessProbe: httpGet: path: /up port: 8080 periodSeconds: 10 livenessProbe: httpGet: path: /up port: 8080 initialDelaySeconds: 30 periodSeconds: 20 --- apiVersion: v1 kind: Service metadata: name: shop-web spec: selector: app: shop-web ports: - port: 80 targetPort: 8080 

With maxUnavailable: 0, a rolling update starts a new pod and waits until its readiness probe succeeds before it stops an old one.

Once the web containers are stateless, a HorizontalPodAutoscaler can add and remove them based on CPU load. It calculates the utilization relative to the CPU requested by the pods, so without resources.requests.cpu in the deployment the autoscaler doesn't scale at all. A PodDisruptionBudget makes sure node upgrades never take down more than one pod at a time:

apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: shop-web spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: shop-web minReplicas: 3 maxReplicas: 40 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70 --- apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: shop-web spec: maxUnavailable: 1 selector: matchLabels: app: shop-web 

The worker deployment has its own replica count, so a large import doesn't slow down the storefront.

Trade-offs and common misconceptions

Microservices are optional

Cloud-native is often equated with splitting a shop into dozens of microservices. That split adds network calls, distributed transactions and a deployment per service, and small teams spend much of their time keeping the pieces in sync. A modular application that is stateless and runs as several identical instances meets every criterion above. Splitting off a service makes sense when one part has clearly different scaling needs or its own team.

The cloud is not automatically cheaper

Elastic capacity saves money for shops with uneven traffic. For a shop with steady load, a few reserved servers can cost less than a fleet of managed services. Data transfer, managed databases and observability tools grow with traffic and are easy to underestimate, so set budgets and spending alerts from the start.

More moving parts to operate

The team no longer replaces disks, but it needs knowledge of containers, pipelines, cloud permissions and distributed failures. A bug can involve the shop, a queue, a worker and a cache at once, and without central logs it takes much longer to find.

The database is still the bottleneck

Application servers scale easily, the database does not. Caching, read replicas and search data that is prepared for queries keep the load on the primary database within limits. A platform that builds every catalog page from complex joins over the raw product tables will hit that limit early, no matter how many web instances it runs.

When a single database server is no longer enough, Aimeos can split the data by domain. Each part of the shop, like products, orders or customers, uses its own database resource if one is configured in config/shop.php (db-product, db-order, db-customer and so on) and falls back to db otherwise. Orders and customer accounts can then live on a different database server than the catalog, so checkout traffic and catalog browsing don't compete for the same server.

The first limit you usually reach is the number of connections. Each PHP worker holds its own database connections, and Aimeos opens its own next to the one of Laravel, up to the limit set in resource/db (3 by default). Even with only one connection per worker, 40 pods with 8 workers each open 320 connections, more than the default max_connections of 151 in MySQL or 100 in PostgreSQL. Calculate this before setting maxReplicas, and put a connection pooler like ProxySQL or PgBouncer in front of the database if the numbers don't fit.

Vendor lock-in

The more proprietary services a shop uses, the harder it becomes to move. Containers, Kubernetes, S3-compatible storage and open source databases keep that option open. Some lock-in can be a fair price for less operating work, as long as it is a conscious decision.

Checklist: is your platform cloud-native?

Copy this list and check it against your own shop or a platform you are evaluating:

  • [ ] Several instances run behind a load balancer without sticky sessions
  • [ ] All files (media, imports, exports, downloads) can be stored in S3-compatible object storage
  • [ ] Sessions, baskets and caches can live in Redis or a similar shared store, and all instances share one encryption key
  • [ ] The application works behind a TLS-terminating load balancer (trusted proxy headers)
  • [ ] There is a documented way to build a container image, with a health check endpoint
  • [ ] Slow tasks run in background workers that scale separately from the web servers
  • [ ] Product search and filtering stay fast at your catalog size, with a search engine option for very large catalogs
  • [ ] All functions are available through documented APIs for a separate frontend
  • [ ] Configuration and credentials can be passed through environment variables
  • [ ] Database schema updates run as a separate deployment step
  • [ ] Logs go to stdout or a central system
  • [ ] One installation can serve several shops, brands or countries with separated data
  • [ ] The platform has been load-tested at your expected peak

If several answers are "possible with custom development", you will be paying for that development yourself.

Conclusion

A cloud-native shop treats servers as replaceable. State lives in shared services, work that can wait runs in the background, every function is reachable through an API, and machines are added or removed by automation. For a Laravel shop with Aimeos, the application side is mostly configuration: Redis for sessions and cache, object storage for all shop files and a worker container for the jobs. Building the image, the deployment pipeline and the managed database is still work your team has to plan for.

What was the hardest part when you made your own shop stateless? Let me know in the comments.