# Best Practices

# Stateless application

When referring to a stateless application, we refer to an application running in a docker container that does not maintain any persistent data within the actual container, such that the container can be terminated at any time without incurring any data loss.

In production, it is recommended that all the application data is distributed. For example, the user sessions can be stored in a distributed redis cache, shared by all the running containers. Application assets, or custom file uploads to be stored in an object storage service like AWS S3. Application logs should be forwarded to a central logging service like AWS CloudWatch logs.

# Databases

When working locally, it's very easy to spin up a database in a docker container and connect your application to it, however in production this might not be ideal. There is a lot of overhead in maintaining a database, in terms of patching, security, monitoring and alerting. When possible, try to use a managed database solution like AWS RDS, Cloud SQL or Azure SQL.

# Observability

In a production environment things can go wrong from time to time. It's important to have the right tools to identify problems early on and get alerted as soon as issues occur. Depending on your cloud provider, you might be able to use managed tools like CloudWatch for logging and alerting, or open source tools such as Prometheus for metric collection and Grafana for visualization.