Liveness trả lời câu hỏi process còn sống không, nên đơn giản và ít dependency. Readiness trả lời app đã sẵn sàng nhận traffic chưa, có thể kiểm database/cache/critical dependency.
Ví dụ:
python
@app.get("/health/live")
async def live():
return {"status": "ok"}
@app.get("/health/ready")
async def ready(db: Annotated[AsyncSession, Depends(get_db)]):
await db.execute(text("SELECT 1"))
return {"status": "ready"}Nếu readiness fail, orchestrator nên ngừng route traffic nhưng không nhất thiết restart process ngay.
Liveness answers whether the process is alive, so it should be simple and depend on very little. Readiness answers whether the app is ready to receive traffic and may check database/cache/critical dependencies.
Example:
python
@app.get("/health/live")
async def live():
return {"status": "ok"}
@app.get("/health/ready")
async def ready(db: Annotated[AsyncSession, Depends(get_db)]):
await db.execute(text("SELECT 1"))
return {"status": "ready"}If readiness fails, the orchestrator should stop routing traffic but does not necessarily need to restart the process immediately.