Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

github.com

38 points by stavepan 14 days ago


10000truths - 13 days ago

"poll every N seconds" for readiness checks is an anti-pattern. The problem is that latency cascades. A dependency chain of M services will have an end-to-end latency of N*M in the worst case and (N*M/2) in the average case, if they all rely on polling to check that the next service is ready.

You should instead rely on backpressure to signal readiness. A service accepts connections immediately, and only blocks the client when the service has to block on something else to procure a response. Systemd takes this approach with UNIX sockets - it creates all the UNIX sockets for each service, and then starts all the services in parallel. The socket buffers queue the messages so that clients can send messages to services that haven't yet started, and the OS scheduler will saturate the available CPU/IO so that the startup of all the services are maximally parallelized.

Obviously, this is not always feasible, especially in cases where you don't control the service(s) you depend on. But to the extent that you do, relying on backpressure instead of polling can markedly improve end-to-end latency.

matthews2 - 14 days ago

Zero dependencies seems like a weird selling point, especially since it depends on Clap, Tokio, a Rust compiler...

A neat project, though. I think that this is best solved in the application itself (e.g. your server starts but returns HTTP errors while the database is unavailable), but being able to retrofit this behaviour into any existing application seems useful. Feels like something very similar should be built into tools like docker-compose.

fumplethumb - 14 days ago

With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well!

I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead.

[0] https://github.com/peter-evans/docker-compose-healthcheck

q3k - 14 days ago

Alternative: write your applications to not depend on the liveness of other services to start up. Your ops will thank you.

hhthrowaway1230 - 14 days ago

Like other say easy to fix this with bash alone. But maybe if you add things like also waiting on other things it can increase your value u a little like also waiting on files, sql queries it can become a pocket knife of waiting for things? Albeit probably people will start saying it will do too much :)

cholindo - 14 days ago

Sometimes waiting for the address is not enough. For example, you might want to wait for a specific API enpoint to return 200 OK, or you might want to wait for database migrations to get applied. Is `is_ready` aiming to cover those cases in the future?

darlingdem - 14 days ago

Seriously?

    is_ready() {
        while ! nc -z $1 $2; do
            echo "Waiting for $1:$2..."
            sleep 1
        done
        echo "$1:$2 is accessible."
    }

    is_ready google.com 443 &
    is_ready x.com 443 &
    wait