12 Factors: Revisiting the 4th Factor - Backing Services
Tags: programming, devops, cloud, productivity
Published: 2023-03-29 07:52:07

We continue with our series of study and review of the [12 factors](https://12factor.net/) for the development of modern applications, inspired by the books of the legendary Martin Fowler.

In previous articles, we discussed the first three factors: [Codebase](https://luizferreira.dev/codebase/), [Dependency Management](https://luizferreira.dev/dependencies/), and [Configurations](https://luizferreira.dev/configuration/). Today, we will address the fourth factor:

## Backing Services

Backing services are external resources used by your application, such as databases, messaging systems, caching services, and other APIs. These services are usually managed by third parties or other teams and are essential for the functioning of your application.

## Treat Backing Services as Attached Resources

One of the main practices of the fourth factor is to treat backing services as attached resources, that is, consume them as if they were an integral part of your application. This implies a consistent approach to accessing and using these services, regardless of their type or provider.

To follow this practice, you should:

1. **Abstract access to services:** Create abstraction layers that hide the specific details of each backing service. This makes it easy to switch providers or migrate to other services without the need for major modifications to the code.

2. **Use configurations to specify backing services:** As mentioned in the [third factor](https://luizferreira.dev/configuration/), configurations should be separated from the code. Thus, it is essential to store connection information to backing services, such as URLs and credentials, in environment variables or other configuration mechanisms.

3. **Decouple backing services:** Ensure that your application can function even if some backing services are not available. Decoupling the application from backing services increases resilience and allows you to continue operating even when facing problems with any of these services.

4. **Monitor and track communication with backing services:** Track and monitor the use and performance of backing services to detect possible bottlenecks, failures, and performance improvements.

## Examples and Tools

Here are some examples of backing services and tools that you can use in your project:

1. **Databases:** PostgreSQL, MySQL, MongoDB, and Redis are examples of backing services in the form of databases. They can be used to store and manage data for your application.

2. **Messaging services:** RabbitMQ, Kafka, and Amazon SQS are messaging services that enable asynchronous communication between components of your application, aiding in scalability and decoupling processes.

3. **Storage services:** Amazon S3, Google Cloud Storage, and Azure Blob Storage are examples of storage services that can be used to store files and other resources for your application.

4. **External APIs:** Some applications may rely on external APIs to obtain information, such as geolocation, weather forecasts, or financial data. These APIs are also considered backing services and should be treated according to the practices mentioned earlier.

5. **Monitoring tools:** Tools like New Relic, Datadog, and Prometheus can be used to monitor and track communication with backing services, helping to identify issues and improve application performance.

6. **Caching services:** Redis, Memcached, and Amazon ElastiCache are examples of caching services that can be used to enhance the performance and speed of your application's responses by storing temporary or frequently used data.

7. **Search services:** Elasticsearch, Solr, and Amazon CloudSearch are search services that can be used to index and search data in your application, providing a faster and more efficient search experience for users.

8. **Authentication and authorization services:** Auth0, Okta, and Firebase Authentication are examples of services that help manage authentication and authorization of users in your application, ensuring the security and privacy of data.

9. **Logging platforms:** Graylog, Logstash, and Amazon CloudWatch are examples of logging services that can be used to collect, analyze, and store logs from your application, aiding in the identification of issues and performance analysis.

10. **Continuous Integration and Continuous Delivery (CI/CD):** Jenkins, GitLab CI/CD, and GitHub Actions are examples of services that can be used to automate the process of integration, testing, and deployment of your application, improving code quality and streamlining the development cycle.

When using backing services, it is important to follow best practices mentioned, such as treating resources as attached resources and ensuring portability between execution environments. Also, when choosing a backing service, consider factors such as scalability, ease of use, cost, support, and the developer community behind the service.

Remember that choosing the right backing service for your project can have a significant impact on the success of your application. Therefore, it is crucial to research and compare different options before making a decision.

## Stay tuned

In this article, we covered the sixth factor of the 12 factors of software development, which is the use of backing services. Using backing services allows you to focus on developing the core functionalities of your application, delegating secondary tasks to specialized and reliable services.

We will continue our journey through the 12 factors in the upcoming articles, exploring even more essential concepts and practices for the development of modern applications. Stay tuned and follow our blog to learn more!

Until next time!