Database Schema & Multi-Tenancy
Comprehensive guide to Sferafy's multi-tenant domain models, Row Level Security (RLS) policies, covering indexes, and materialized reporting views.
On this page(4)
Row Level Security (RLS) & Multi-Tenant Model
In Sferafy, all data entities are governed by strict Row Level Security (RLS) policies. Every read, write, update, and deletion operation is filtered automatically by the user's cryptographically verified company membership.
Tenants operate in complete digital isolation: users belonging to Company A can never view, alter, or infer the existence of records belonging to Company B, even if a direct record identifier is supplied.
High-Performance Identity & Role Evaluation
To prevent performance bottlenecks across complex organizational trees, identity resolution operates through pre-compiled, cached evaluation gates:
• Tenant Resolution: Resolves the authenticated user's verified company workspace in sub-millisecond time.
• Employee Mapping: Securely links user authentication sessions to corporate employee profiles.
• Role Verification: Evaluates whether the caller holds Company Administrator, HR Lead, Finance Officer, or Managerial privileges.
Domain Entity Architecture Summary
The data architecture encapsulates 6 core operational domains:
- Core Tenancy & People: Organization units, employee profiles, department hierarchies, and system roles.
- Leaves & Availability: Vacation requests, multi-tier approvals, leave balances, and comp-time ledgers.
- Invoicing & Hardware: B2B client invoices, Stripe payments, and hardware equipment registry custody.
- Knowledge & Collaboration: Standard Operating Procedure (SOP) wiki, policy sign-offs, and company event schedules.
- Governance & Whistleblower: Zero-knowledge anonymous grievance box, encrypted message channels, and SOC 2 access reviews.
- Engineering & Rotations: On-call paging shifts, incident responder logs, coverage rules, and 1-on-1 sync notes.
Real-Time Telemetry & Zero-Latency Performance
To ensure the executive and HR dashboards load instantaneously (<15ms) across growing organizations with thousands of employees, Sferafy utilizes real-time materialized aggregate views.
Key headcounts, active leave distributions, pending invoice totals, and compliance status indicators update automatically on high-impact events without sluggish database recalculations.