GOAL — To deal with db connection issues that are fluctuating .

what if we don’t retry transient connection errors and how does retries in a regulated way help ? —

A request that was about to complete may fail , similarly many other requests like this. So they were using connection but minor fluctuations caused full failure , so now client has to retry again fully . SOLUTION : Retries help to try atomic db units of work —> implies less failures —> better concurrency and resource usage Even full endpoint retries are good as we still prevent high client to server calls .

Your code
↓
SQLAlchemy AsyncSession
↓
SQLAlchemy Engine
↓
DBAPI driver (e.g. asyncpg)
↓
TCP connection to DB

For retries at endpoint level or sub-functions inside endpoints where auth has already been established.

Auth tokens — are for entering a request , they may expire while request is being processed and that’s okay . We may do some duration check of expiry for very long running bg tasks .

  1. when we use session or begin it explicitly for first time it gets a connection from conn pool .
  2. we have to use commit to write chnages to db and rollback to cleanup session state when error happens . session close at end of function . using aysnc with automatically closess connection at end and also rolls back to cleanup session in case of errors .

can we retry at sub-functions level and is it better to retry at subfunctions level ?