Building a cloud-friendly application

Larry Garfield


Larry implements Huggable
  • Director of DX,
  • PHP-FIG Core Committee
  • implements Huggable
Software is eating the world, and cloud is eating software. (Source: @bassamtabbara)

What is cloud

What is
The Cloud?

These are separate questions...

The Cloud™: noun

Someone else's hard drive

Cloud computing: noun

Abstracting away physical infrastructure

Disposable application design

What makes an application

They're not rules

They're more like guidelines...

They're more like guidelines

Split code from content


  • Provided by developer
  • Carefully tested
  • Lives in version control
  • Read-only runtime


  • Provided by users
  • Frequently ad hoc
  • Lives in DB or filesystem
  • Writeable runtime
Don't mix the filesystems

Your application is disposable.
Your data is not.

Data flow

Code flows up to production, data flows down.

You don't get an in-between option


Cleanly separate "Dev provided" and "user provided" files

What is configuration?

Does config come from the developer or the user?

Git or Database?

Drupal Config Management

Drupal 8
  1. Configure in UI / DB
  2. Export to YAML
  3. Commit to Git
  4. Push / Pull
  5. Import back to DB



What happens at runtime
stays at runtime

Application slots into cluster

Dependency inject your environment

  • DB credentials (Solr, Redis, etc.)
  • API keys
  • All paths on disk
  • Domain names

Environment variables

          // PHP

          // Node.js

          // Go


Need glue code / Symfony 3

// platform_parameters.php
    $relationships = json_decode(base64_decode(getenv('PLATFORM_RELATIONSHIPS')), true);

    foreach ($relationships['database'] as $endpoint) {
        if (!empty($endpoint['query']['is_master'])) {
            $container->setParameter('database_driver', 'pdo_'.$endpoint['scheme']);
            $container->setParameter('database_host', $endpoint['host']);
            $container->setParameter('database_port', $endpoint['port']);
            $container->setParameter('database_name', $endpoint['path']);
            $container->setParameter('database_user', $endpoint['username']);
            $container->setParameter('database_password', $endpoint['password']);
$container->setParameter('kernel.secret', getenv('PLATFORM_PROJECT_ENTROPY'));
 / Express.js

const platformsh = require('platformsh-config');
let config = platformsh.config();

const credentials = config.credentials('database');

const connection = await mysql.createConnection({
    port: credentials.port,
    user: credentials.username,
    password: credentials.password,
    database: credentials.path,

var app = express();
// ...

 / Go

package conf
import (
  psh ""
var PshConfig = createPshConfigObj()

func createPshConfigObj() *psh.RuntimeConfig {
  config, _ := psh.NewRuntimeConfig()
  return config

package main

func main() {
  engine := gin.Default()
  // ...
  err := ginInstance.Run(":" + conf.PshConfig.Port())

Use DotEnv (.env files)

(Many to pick from in every language)

Trusted domains

(App-specific configuration)



Dependency inject your environment

User-configured connections


  1. Ask for DB credentials
  2. Ask user for basic site info
  3. Write credentials to config file
  4. Populate DB
  5. Write basic site info to config file/DB
  6. Profit!!!


Better installers

  • Pre-include connection glue
  • Installer skips pre-populated values
  • Do not download from installer

Avoid lock-in

Always be able to
take your business elsewhere.

Use Free Software

Use replaceable services

Google has killed...

  • Reader
  • iGoogle
  • Google Talk
  • Google Health
  • Knol
  • Google Insights
  • Picnik
  • Buzz
  • Aardvark
  • Sidewiki
  • Notebook
  • Dictionary
  • Labs
  • Wave
  • SearchWiki
  • Dodgeball
  • Jaiku
  • Lively
  • Page Creator
  • Plus
  • Zeitgeist
  • Answers
  • Google X
  • Catalog
  • Web Accelerator
  • Video Player
  • Sets
  • SearchMash
  • Writely
  • Plus+

Source: WordStream (2015)


  • MySQL/MariaDB
  • PostgreSQL
  • RabbitMQ
  • Solr/Elasticsearch
  • InfluxDB


  • Amazon RDS
  • Amazon DynamoDB
  • Azure Cosmos DB
  • Anything you can't replace in a day

To summarize...

Remember what they say when you assume

Larry Garfield


Director of Developer Experience

Idea to Cloud Hosting

Stalk us at @PlatformSH