# ADR-0002: Streaming Protocol

## Status
Accepted

## Context
NexusCRM requires real-time updates for:
- Record changes
- Notifications
- Dashboard updates
- Collaboration features

We evaluated multiple approaches:
1. **Polling** - Simple but inefficient
2. **Server-Sent Events (SSE)** - One-way, good browser support
3. **CometD (Bayeux)** - Salesforce-compatible, bidirectional
4. **WebSocket** - Full-duplex, efficient

## Decision
Implement **dual protocol support**:

1. **CometD/Bayeux** (primary) - For Salesforce compatibility
   - `/cometd/:version/handshake`
   - `/cometd/:version/connect`
   - `/cometd/:version/subscribe`
   - `/cometd/:version/disconnect`

2. **WebSocket** (fallback/modern) - For better performance
   - `/ws` - Single endpoint with message-based protocol

**Session Management:**
- UUID-based client IDs (not hardcoded)
- Session timeout with cleanup (30 min default)
- Channel subscription tracking

## Consequences

**Positive:**
- Salesforce API compatibility maintained
- Modern clients get WebSocket performance
- Single session manager for both protocols
- Graceful degradation possible

**Negative:**
- Two protocols to maintain
- More complex than single approach
- Testing requires coverage of both paths

**Implementation:**
- `streaming/session_manager.go` - Shared session management
- `rest/streaming_handler.go` - CometD endpoints
- `rest/websocket_handler.go` - WebSocket endpoint
