Nightly Sync
Nightly Sync is the scheduled batch process that updates all integration data from Vendors. It runs daily after US market close to capture end-of-day positions and prices.
Schedule
Section titled “Schedule”- Timing: US evening (after market close)
- Frequency: Every US business day
- Duration: Varies by number of integrations (typically 2-4 hours)
Process Flow
Section titled “Process Flow”sequenceDiagram
participant S as Scheduler
participant C as Command
participant Q as Queue
participant W as Worker
participant V as Vendor/S3
participant DB as Database
S->>C: Trigger sync command
C->>DB: Get all active integration mappings
C->>Q: Create job per mapping
loop For each mapping
Q->>W: Dequeue job
W->>V: Fetch data (API or S3)
V-->>W: Return data
W->>W: Parse and transform
W->>DB: Update records
W->>Q: Mark complete
end
What Gets Synced
Section titled “What Gets Synced”| Data Type | Source | Action |
|---|---|---|
| Accounts | Vendor | Create/Update/Deactivate |
| Positions | Vendor | Replace with latest |
| Holdings | Vendor | Update quantities and values |
| Prices | Morningstar | Update security prices |
Sync by Integration Type
Section titled “Sync by Integration Type”File-based Sync
Section titled “File-based Sync”- Read LATEST files from S3
- Parse files for each Rep Code
- Match accounts to existing records
- Update positions and holdings
- Handle deleted accounts
API-based Sync
Section titled “API-based Sync”- Load OAuth credentials for mapping
- Call Vendor API endpoints
- Transform response to internal format
- Update database records
- Handle errors and retries
Job Processing
Section titled “Job Processing”Queue Structure
Section titled “Queue Structure”Each integration mapping becomes a queue job:
Job { integration_mapping_id: 12345 vendor: "schwab" advisor_id: 67890 type: "api_based"}Retry Logic
Section titled “Retry Logic”- Failed jobs are retried (up to 3 attempts)
- Exponential backoff between retries
- Permanent failures logged for investigation
Monitoring
Section titled “Monitoring”Key Metrics
Section titled “Key Metrics”| Metric | Alert Threshold |
|---|---|
| Sync completion rate | < 95% |
| Average job duration | > 60s |
| Failed jobs | > 5% |
| Stale data (not updated) | > 24 hours |
- Application logs: Job start/end, errors
- File logs: Raw API requests/responses
- Database: Sync history per mapping
Dashboards
Section titled “Dashboards”- Sync completion status by Vendor
- Error rate trends
- Processing time distribution
Common Issues
Section titled “Common Issues”Sync Not Running
Section titled “Sync Not Running”- Check scheduler health
- Verify queue workers are running
- Check for infrastructure issues
High Failure Rate
Section titled “High Failure Rate”- Vendor API may be down
- Rate limiting issues
- Credential expiration
Slow Sync
Section titled “Slow Sync”- Large data volumes
- Vendor API latency
- Database bottlenecks
Missing Updates
Section titled “Missing Updates”- Vendor didn’t send updated files
- Collector failed to download
- Mapping deactivated
Troubleshooting
Section titled “Troubleshooting”- Check job status - Look at queue monitoring
- Review logs - Application logs for errors
- Check file logs - Raw Vendor responses
- Verify data - Compare S3 files with DB
Manual Sync
Section titled “Manual Sync”For debugging or recovery, sync can be triggered manually:
# Sync specific integration mappingphp artisan integration:sync --mapping-id=12345
# Sync all mappings for a vendorphp artisan integration:sync --vendor=schwabRelated
Section titled “Related”- Data Issues - Investigating sync problems
- Collector - File-based data source
- API Integrations - API-based sync