We manage thousands of client portfolios and need an automated rebalancing backend that advisors can run quarterly or on demand. For each portfolio, compare current holdings to the client’s target model and produce concrete buy/sell orders to bring allocations back within tolerance while minimizing trading costs and tax impact. Advisors should be able to run a dry run, review the proposed trades, and approve them for execution. The service must provide progress/status for long-running batches and keep a full audit trail.

Operationally, the web API should orchestrate only: a request enqueues one or more jobs and returns immediately; a worker fleet performs the heavy calculations in the background and stores the resulting orders and metrics in the database. Our stack is Python with FastAPI, MySQL for storage, and a RabbitMQ/Celery task queue.

Please deliver the core backend: data model, API endpoints (kickoff, status, results), job orchestration and worker flow (including idempotency and retries), and a portfolio-level rebalancing algorithm that accounts for transaction costs and basic tax considerations.