Twelve-Factor WordPress App #4: Backing Services

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.

In Practice

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.

Turning a WordPress site into a Twelve-Factor App

  1. Codebase
  2. Dependencies
  3. Config
  4. Backing Services
  5. Build, release, run
  6. Processes
  7. Port binding
  8. Concurrency
  9. Disposability
  10. Dev/prod parity
  11. Logs
  12. 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.

Get our latest updates & occasional tips on building better WordPress sites

Follow @rootswp on Twitter