Having implemented both approaches across multiple Apriso deployments, I can provide some balanced perspective on this architectural decision.
API Security & Business Logic
The REST API isn’t just about authentication - it enforces critical business rules that direct DB access bypasses:
- Status calculations that combine multiple tables
- Timezone conversions for global operations
- Unit of measure conversions
- Security filtering based on plant/area access
- Audit trail generation for data access
When you query the database directly, you’re seeing raw data that may not represent the actual business state. For example, a machine status might be ‘RUNNING’ in the MACHINE_STATUS table but the API returns ‘STARVED’ because it checks material availability from related tables.
Direct DB Risks & Upgrade Impact
Direct database access creates technical debt:
- Schema changes between versions break your queries
- Calculated fields require you to duplicate Apriso’s business logic
- No protection against reading inconsistent data during transactions
- Database maintenance operations (reindexing, partitioning) can impact your queries
I’ve seen companies spend weeks refactoring dashboard queries after an Apriso upgrade because table structures changed.
Data Freshness Reality
The API cache concern is valid but manageable:
- Use
Cache-Control: no-cache header for critical endpoints
- Configure API gateway cache TTL per endpoint
- For true real-time needs, use WebSocket subscriptions:
ws://apriso-server/api/v1/shopfloor/events
Subscribe to: machine.status.changed
WebSockets push updates immediately (sub-second) without polling overhead. This is far superior to either REST polling or DB polling.
Auditability & Compliance
In regulated industries (pharma, aerospace), direct DB access can violate compliance requirements:
- No audit trail of who accessed what data
- Bypasses data retention policies
- Makes it harder to demonstrate data integrity for audits
The API automatically logs all access, which is critical for 21 CFR Part 11 compliance.
Recommended Hybrid Approach
- Primary path: Use REST API for all operational dashboards
- Real-time events: Implement WebSocket subscriptions for sub-second updates
- Analytics/BI: Use Apriso’s official reporting views for data warehouse ETL
- Emergency only: Direct DB for troubleshooting, never in production code
Performance Optimization
If API performance is still a concern:
- Implement client-side caching with smart invalidation
- Use GraphQL-style field selection to reduce payload size
- Batch multiple requests into single API call where supported
- Deploy API gateway closer to shop floor (edge computing)
The slight performance cost of the API is insurance against data inconsistency, upgrade breaks, and compliance issues. In my experience, the teams that chose direct DB access all eventually migrated to the API after encountering these problems - usually during a critical upgrade window.
Bottom Line: Use the API. If performance is insufficient, optimize the API infrastructure rather than bypassing it. The architectural integrity is worth more than the marginal performance gain from direct DB access.