# Background Processor The Background Processor continuously polls the Redis transaction buffer and executes transactions against the main database. ```{contents} Table of Contents :depth: 2 :local: true ``` ## Core Implementation Key code from `background_processor.py`: ```{literalinclude} ../../../ccat_ops_db_api/transaction_buffering/background_processor.py :emphasize-lines: 10-20, 71-80 :language: python :lines: 19-100 ``` ## Processing Loop 1. **Check buffer size** (LLEN) 2. **Check database connectivity** 3. **Pop transaction** (RPOP) 4. **Execute transaction** on main database 5. **Capture LSN** after commit 6. **Track replication** via LSN tracker 7. **Cleanup or extend cache** based on replication ## Configuration ```bash BACKGROUND_PROCESSING_INTERVAL=1.0 # seconds TRANSACTION_RETRY_ATTEMPTS=3 TRANSACTION_RETRY_DELAY=5 # seconds ``` ## Health Monitoring The processor reports health via `/health` endpoint: ```json { "background_processor": { "status": "running", "last_run": "2025-01-01T00:00:05Z", "transactions_processed": 150 } } ``` ## Next Steps - {doc}`lsn-tracking` - How replication is tracked - {doc}`../../development/debugging-buffering` - Troubleshooting