Understanding Platform.sh Deployment Architecture

Immutable Infrastructure and Git-based Workflow

Each Platform.sh environment is an isolated containerized build derived from a Git branch. Infrastructure is recreated on every push, promoting consistency but requiring careful hook management and runtime configuration discipline.

Key Abstractions

  • Services (e.g., PostgreSQL, Redis) defined in .platform/services.yaml
  • Relationships injected via base64-encoded environment variables
  • Build, deploy, and start hooks in .platform.app.yaml

Common Enterprise-Grade Issues

1. Misconfigured Build Hooks

Incorrect dependency installation or build-time scripts often result in apps running with incomplete libraries or miscompiled assets.

hooks:
  build: |
    npm ci
    npm run build
  deploy: |
    node scripts/migrate.js

Ensure all build artifacts are generated in the build phase; the deploy phase cannot mutate build results.

2. Volume Persistence Assumptions

Files written to the file system during runtime are ephemeral unless directed to /persistent. Misunderstanding this leads to data loss on redeploys.

3. Route Incompatibilities in Multi-App Projects

Platform.sh routing (defined in .platform/routes.yaml) may silently fail if apps expect conflicting or wildcard subdomains.

https://{default}/: app:http
https://api.{default}/: app:api

4. Relationship Injections Not Matching Service Names

Discrepancies between relationship keys and service names often cause null connections at runtime. Validate relationships entries align with the services config.

relationships:
  database: "postgres:postgresql"

5. Insufficient Resource Allocation in Enterprise Plans

High-traffic apps with large memory footprints or long-running workers may exhaust quotas silently. Platform.sh doesn't always surface container memory exhaustion clearly.

Diagnosing Problems Effectively

Use Platform CLI and Logs

The platform CLI provides environment status, logs, and SSH access:

platform ssh
platform logs --service app --type access
platform environment:info

Hook Phase Isolation

Use explicit logging inside each hook to separate build and runtime issues:

echo "[BUILD PHASE] Starting NPM install"
npm ci

Trace Relationship Injection Failures

Dump the PLATFORM_RELATIONSHIPS variable to verify connection strings:

echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq

Pitfalls When Scaling Enterprise Workloads

Background Workers and Asynchronous Tasks

Platform.sh doesn't natively support long-running processes. Using cron jobs or web requests for job execution can lead to timeout or parallelism issues.

Data Store Lock-in

Swapping databases or services mid-project requires re-declaring and re-wiring environments. In enterprise setups, this causes downtime if not planned correctly.

Step-by-Step Fixes

1. Validate Configuration Schema

Use the CLI validator:

platform validate

2. Declare Volumes Explicitly

mounts:
  "/data":
    source: storage
    source_path: data

3. Pin Service Versions

postgresql:
  type: postgresql:13
  disk: 1024

4. Split Apps for Isolation

For large systems, consider decoupling into multiple app containers with separate lifecycle management, using app:api, app:frontend, etc.

5. Instrument Custom Monitoring

Integrate New Relic or Datadog agents using start hooks or sidecar processes (within Platform.sh limits).

Best Practices for Long-Term Maintainability

Keep Config in Source Control

All environment changes should be committed to Git to maintain auditable, reproducible deployments.

Use Environment Branching Strategically

Develop isolated feature branches to test infrastructure and configuration changes without risking mainline environments.

Integrate CI Pipelines

Use GitHub Actions or GitLab CI to run pre-deployment checks like YAML validation and test coverage before pushing to Platform.sh.

Review Resource Usage Periodically

Monitor container CPU/memory over time using the Platform.sh metrics dashboard or API to prevent unexpected throttling.

Conclusion

Platform.sh simplifies infrastructure but comes with a learning curve, especially in enterprise contexts. Misconfigurations in routing, volumes, service declarations, and build hooks can cause failures hard to trace without deep platform awareness. By following structured diagnostics and aligning with Platform.sh's immutable and declarative principles, teams can mitigate risks, streamline scaling, and leverage the platform effectively for high-performance workloads.

FAQs

1. Can I run background workers continuously on Platform.sh?

No. Background workers must be triggered via cron or queue processing endpoints. Platform.sh does not support always-on processes.

2. How do I handle file uploads?

Files must be stored in the persistent mount path like /data, or uploaded directly to external object stores like S3 for durability.

3. What happens to data between builds?

Only data in mounted volumes (e.g., /data) or external services persist. Files in the container root are ephemeral and cleared on redeploys.

4. How do I debug routing issues?

Review routes.yaml and confirm domain mapping matches the app name and port. Use platform routes to inspect active rules.

5. Can I use Dockerfiles directly on Platform.sh?

No. Platform.sh does not use Dockerfiles; it uses a declarative YAML-based build pipeline defined in .platform.app.yaml.