In Compose, a plain depends_on: [db] guarantees only ordering of container creation and start. The dependent service starts as soon as the database container is running, which is typically several seconds before the database accepts connections. The result is an application that crashes on first boot with a connection-refused error and recovers only because of a restart policy.
Compose V2 supports a long form that actually waits: depends_on: db: condition: service_healthy. That requires the db service to define a healthcheck, because the condition is evaluated against Docker's health status. Without a healthcheck on the dependency, Compose errors out rather than waiting forever.
Two other conditions exist: service_started, which is the default and equivalent to the short form, and service_completed_successfully, which waits for a one-shot container such as a migration job to exit zero. These conditions apply to docker compose up; they are ignored by docker compose run unless dependencies are started.