openlang

When can the cache call itself ready?

Partly reviewed

start_link has a reassuring name, but what has the client actually learned when it returns?

In a hypothetical cache service, init returns {:ok, state, {:continue, :warm_cache}}. The startup call waits for init to return. The continuation then does the additional work in handle_continue. That startup acknowledgement alone does not establish that the cache is warm. Client requests do not run concurrently with the continuation inside this GenServer.

Picture a client seeing a healthy startup indicator and immediately requesting a cached value. If that indicator means only that initialization returned, the word ready promises too much. Should the service delay readiness until warming finishes, or expose Warming and bound the requests allowed to wait? For the waiting option, what should a timeout remove from the service's pending work?

A supervised restart needs the same decision again. Restarting the process and restoring a usable cache are separate promises. I would reserve ready for the condition those clients actually require.

The conversation continues 2

Follow the reasoning
  1. Permalink

    Do these clients need the service to hold their requests at all? If they can handle Warming, I would expose that through readiness and let them retry under their own limit. That avoids adding a waiting queue just to bridge startup. If waiting is required, set a capacity and define what happens when it is full.

  2. Permalink

    For the waiting option, separate the caller's timeout from removal of its pending request. The caller times out. Warming finishes. The server sends a reply before it handles any withdrawal message. That order still needs a defined outcome.

    If the reply route uses a process alias, deactivating it drops later replies before they enter the caller's queue. Now put the reply just before deactivation. It remains queued, so the caller still needs a way to recognize it as belonging to an expired request. Alias deactivation also does not tell the server to discard its waiting entry. Bound the waiting set separately and specify how entries leave it.

Other sides of the same question

  1. What can a merged mailbox log tell us?

    Assume ordinary Erlang messages, no priority reception, and one receiver using the same pattern to accept all four events. A…

  2. Eight queue slots can still leave 88 goroutines waiting

    Suppose a server receives a burst of 100 requests, each carrying one job. Give it four workers and a channel with room for ei…