Twelve-factor app methodology

To effectively design and build applications for the cloud, you should understand the Twelve-Factor App methodology.

Factor 1: One codebase tracked in revision control with multiple deployments
Use one codebase for tracking and revision control, and from that codebase, you can deploy many times. Use IBM Bluemix DevOps Services or Cloud Foundry deployment tools with tools such as IBM UrbanCode Deploy, Jenkins, Gradle, or an equivalent.

Factor 2: Explicitly declare and isolate dependencies
Use IBM Bluemix deployable units such as Java Liberty and Node.js buildpacks to manage runtime dependencies. For example, the package.json file for a Node.js application lists all external dependencies.

Factor 3: Store configuration in the environment
Provide any additional configuration information through the VCAP_SERVICES environment variable. Services that are bound to an application also populate the VCAP_SERVICES variable with their configuration attributes.

Factor 4: Treat backing services as attached resources
Bind services to applications by using the Bluemix web UI dashboard or use the bx service create and bx service bind commands to attach services to an application.

Factor 5: Strictly separate build and run stages
In IBM Bluemix, when you use the bx app push command to deploy, the application is staged, assembled, and then stored as an immutable object in the build phase. Then, the object is copied to a container and started in the run phase.

Factor 6: Execute the app as one or more stateless processes
When you design applications, use multiple processes or services as needed. IBM Bluemix application instances are stateless and do not have persistent file storage. Avoid dependencies on sticky sessions and keep session data in a persistent store to ensure traffic can be routed to other processes without service disruption.

Factor 7: Export services by using port binding
IBM Bluemix provides a process or service with a port for binding and then handles routing traffic to the process over this port automatically. Application code reads the port from the environment and binds to this port accordingly.

Factor 8: Scale out by using the process model
Horizontal scaling of application instances in IBM Bluemix can be explicitly performed by using the bx app scale command or automatically scaled by using the Auto-Scaling service.

Factor 9: Maximize robustness with fast startup and graceful shutdown
Use a disposable approach to the design of a process in the application. There should be minimal startup actions required. When a process is terminated, it should exit with minimal housekeeping. This improves robustness and responsiveness to horizontal scaling events.

Factor 10: Keep development, staging, and production as similar as possible
Spaces in IBM Bluemix provide an effective method to separate different levels of an application. This approach enables agile software delivery and continuous integration.

Factor 11: Treat logs as event streams
In IBM Bluemix, processes should write log data as an unbuffered event stream to standard out. The Bluemix Loggregator accumulates log data across various components of the application and Cloud Foundry environment and provides it for viewing by using the bx app logs command or exporting to a third-party logging service.

Factor 12: Run administrator and management tasks as one-off processes
Design tasks that need to run once or occasionally into separate components that can be run when needed instead of adding the code directly into another component. For example, if an application needs to migrate data into a database, place this task into a separate component instead of adding it to the main application code at startup.

Related links