(Source: @bassamtabbara)
What is cloud
computing?
What is
The Cloud?
These are separate questions...
Someone else's hard drive
Abstracting away physical infrastructure
Disposable application design
Your application is disposable.
Your data is not.
You don't get an in-between option
Cleanly separate "Dev provided" and "user provided" files
Does config come from the developer or the user?
Git or Database?
Decide
// PHP
getenv('foo');
// Node.js
process.env["foo"];
// Go
os.Getenv("foo");
// Java
System.getEnv("foo");
Etc.
getenv('foo');
$_ENV['foo'];
$_ENV['foo']['bar'];
Only ever use getenv()
Need glue code
// platform_parameters.php
if (getenv('PLATFORM_RELATIONSHIPS')) {
$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']);
break;
}
}
}
$container->setParameter('kernel.secret', getenv('PLATFORM_PROJECT_ENTROPY'));
composer require platformsh/symfonyflex-bridge
function mapPlatformShEnvironment() : void
{
$config = new Config();
$secret = getenv('APP_SECRET') ?: $config->projectEntropy;
setEnvVar('APP_SECRET', $secret);
$appEnv = getenv('APP_ENV') ?: 'prod';
setEnvVar('APP_ENV', $appEnv);
mapPlatformShDatabase('database', $config);
if (!getenv('MAILER_DSN')) {
mapPlatformShMailer($config);
}
}
// ...
composer require platformsh/laravel-bridge
function mapPlatformShEnvironment() : void
{
$config = new Config();
$secret = "base64:" . base64_encode(substr(
base64_decode($config->projectEntropy), 0, 32));
setEnvVar('APP_KEY', $secret);
$secure_cookie = getenv('SESSION_SECURE_COOKIE') ?: 1;
setEnvVar('SESSION_SECURE_COOKIE', $secure_cookie);
mapAppUrl($config);
mapPlatformShDatabase('database', $config);
mapPlatformShRedisCache('rediscache', $config);
mapPlatformShRedisSession('redissession', $config);
}
// ...
package sh.platform.template;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import sh.platform.config.Config;
import sh.platform.config.MySQL;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
@Bean(name = "dataSource")
public DataSource getDataSource() {
Config config = new Config();
MySQL database = config.getCredential("database", MySQL::new);
return database.get();
}
}
package sh.platform.template.spring.kotlin
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import sh.platform.config.Config
import sh.platform.config.MySQL
import javax.sql.DataSource
@Configuration
class DataSourceConfig {
@Bean(name = ["dataSource"])
fun getDataSource(): DataSource {
val config = Config()
val database = config.getCredential("database") { MySQL(it) }
return database.get()
}
}
const platformsh = require('platformsh-config');
let config = platformsh.config();
const credentials = config.credentials('database');
const connection = await mysql.createConnection({
host: credentials.host,
port: credentials.port,
user: credentials.username,
password: credentials.password,
database: credentials.path,
});
var app = express();
// ...
app.listen(config.port);
package conf
import (
psh "github.com/platformsh/config-reader-go/v2"
)
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())
}
composer.json
{
"autoload": {
"files": ["extra-bridge.php"]
}
}
Only works if your app reads env vars...
Use DotEnv (.env
files)
(Many to pick from in every language)
(App-specific configuration)
Constants? Static config files?
Dependency inject your environment
Cloud
Always be able to
take your business elsewhere.
227 services total!
Source: Google Graveyard (2021)
Use Free Software
Use replaceable services
There is no industry consensus yet regarding the properties of microservices, and an official definition is missing as well.
(Sources: Wikipedia, Martin Fowler)
Every microservice treats every other microservice as a separate 3rd party
that may as well be a different company.
Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.
"If one of your microservices going down means the others don't work, you don't have a microservice; you have a distributed monolith."
—A few dozen people
So if microservices aren't for me, what is?
You've probably already done this
Cron jobs
Queue workers
"Admin" application
API app
All asynchronous
Remember what they say when you assume