# Building Healthy Services | Cycle.io

Canonical URL: https://cycle.io/learn/building-healthy-services

## Building Healthy Services.

In modern container orchestration, ensuring that services are healthy and available is key to maintaining reliable application performance. **Health checks**, **restarts**, and **failure detection** are three critical mechanisms that support this.

### Health Checks

Health checks determine whether a containerized application is running as expected. There are two main types:

-   **Liveness Probes:** These check if a container is still operational. If a container fails this check, the orchestrator restarts it. This prevents the application from being stuck in a failed state.
-   **Readiness Probes:** These ensure the container is ready to handle requests. A container may be alive but not yet ready to serve traffic, so this probe prevents routing until the container is fully functional.

Common implementations of health checks include HTTP endpoints, executing commands, or TCP socket checks.

Guides Docs

Using Deployment Health Checks In a Rainbow Deployment

Learn how use health checks to facilitate rainbow deployments on Cycle Platform

<https://cycle.io/docs/guides/deployment-health-checks>

### Restarts

When containers fail or become unhealthy, the platform may automatically restart them. Scenarios that trigger restarts include:

-   **Crash Recovery:** When a container crashes due to an internal error, it is restarted to recover.
-   **Liveness Probe Failures:** If the container fails its liveness check, it is restarted.
-   **Resource Exhaustion:** If a container exceeds its allocated CPU or memory, the system may kill and restart it to stabilize resources.

Restart policies control how restarts are handled. Common policies include:

-   **Always:** Restart the container regardless of the exit status.
-   **On-failure:** Restart only if the container exits with an error.
-   **Never:** Do not restart automatically.

### Failure Detection

Failure detection involves recognizing when a container or its underlying infrastructure is experiencing problems. Key methods include:

-   **Health Check Failures:** Continuous failure of health checks signals an unhealthy state.
-   **Node Monitoring:** The platform monitors the health of the servers (nodes) hosting the containers. If a node fails, workloads are shifted to other nodes.
-   **Resource Metrics:** Monitoring CPU, memory, and other resource usage helps predict potential container failures due to resource limits.

Monitoring tools and alerts enhance failure detection, helping teams to intervene before failures escalate.

### Best Practices

-   **Proper Probe Configuration:** Ensure liveness and readiness probes are correctly set up to avoid unnecessary restarts or false failure detections.
-   **Use Appropriate Restart Policies:** Tailor restart policies based on the application's requirements. For instance, use `on-failure` for applications with clear exit codes and `always` for stateless services.
-   **Resource Monitoring and Limits:** Monitor resource usage and tune limits to avoid resource-related failures.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
