Deployment Overview
ContractShield supports three deployment models. Choose based on your latency requirements and architecture.
Comparison
| Model | Latency | Complexity | Use Case |
|---|---|---|---|
| Embedded | ~1ms | Low | Single service, monolith |
| Sidecar | ~2-5ms | Medium | Kubernetes, microservices |
| Centralized | ~5-20ms | High | Multi-service, shared policies |
Embedded (Recommended Start)
The PDP runs inside your application process.
import { contractShield } from '@cshield/pep-express';
app.use(contractShield({ contractsDir: './contracts',}));Pros:
- Lowest latency
- Simplest setup
- No network dependencies
Cons:
- Contracts bundled with app
- Restart required for updates (unless using Pro hot-reload)
Sidecar
The PDP runs as a separate container alongside your app.
services: api: image: your-api environment: - CONTRACTSHIELD_URL=http://pdp:8080
pdp: image: contractshield/sidecar volumes: - ./contracts:/contractsimport { createClient } from '@cshield/client';
const shield = createClient({ url: 'http://localhost:8080',});
app.use(async (req, res, next) => { const decision = await shield.check(req); if (!decision.allowed) { return res.status(403).json(decision.error); } next();});Pros:
- Update contracts without app restart
- Consistent policies across languages
- Better resource isolation
Cons:
- Network latency
- Additional container to manage
Centralized
A shared PDP service for multiple applications.
┌─────────┐ ┌─────────┐ ┌─────────┐│ App A │ │ App B │ │ App C │└────┬────┘ └────┬────┘ └────┬────┘ │ │ │ └───────────────┼───────────────┘ │ ┌──────┴──────┐ │ Central │ │ PDP │ └─────────────┘Pros:
- Single source of truth
- Centralized audit logs
- Cross-service policies
Cons:
- Single point of failure (needs HA)
- Higher latency
- More complex ops