Factor #4: Backing Services
Treat backing services as attached resources
A backing service is any service the app consumes over the network as part of its normal operation. Examples include datastores (such as MySQL or CouchDB), messaging/queueing systems (such as RabbitMQ or Beanstalkd), SMTP services for outbound email (such as Postfix), and caching systems (such as Memcached).
In addition to these locally-managed services, the app may also have services provided and managed by third parties. Examples include SMTP services (such as Postmark), metrics-gathering services (such as New Relic or Loggly), binary asset services (such as Amazon S3), and even API-accessible consumer services (such as Twitter, Google Maps, or Last.fm).
Obviously by far is the most common backing service in WP land is MySQL. Memcached is probably next up but many WP sites these days are also using 3rd party services/APIs such as S3, Twitter, and SendGrid.
Fortunately for us, the important outcome of treating backing services as attached resources is that it's mostly taken care of by a proper Config.
The code for a twelve-factor app makes no distinction between local and third party services. To the app, both are attached resources, accessed via a URL or other locator/credentials stored in the config. A deploy of the twelve-factor app should be able to swap out a local MySQL database with one managed by a third party (such as Amazon RDS) without any changes to the app’s code.
Let's use MySQL as an example. The most standard setup is running it locally on your application server. Your next step would probably be moving it to its own separate server.
This change would only require a deploy with new environment variables. Since your config already references those, no code would need to be changed.
Then you might need to scale your DB out even more by using Amazon RDS. Once again you wouldn't need any code changes. Just update your env vars with your new DB credentials and re-deploy.
- Backing Services
- Build, release, run
- Port binding
- Dev/prod parity
- Admin processes
Want to turn your WordPress site into a Twelve-factor App? Bedrock is a modern WordPress stack to help you get started with the best tools and practices.