Humanis — Mobile Attendance Optimization
A multi-tenant PHP mobile-attendance API optimized by grouping reusable database connections by tenant and connection class, without risking cross-tenant context.


Business context
Humanis serves mobile attendance requests across multiple client database contexts. The attendance flow became slow because each query opened a new database connection, adding avoidable work throughout the request lifecycle.
Because every tenant and connection class can target a different database context, a single global connection is not safe. The optimization needed to reduce connection creation while preserving strict separation between tenant and connection-class contexts.
The challenge
Using one singleton database connection could return the wrong tenant or connection-class context. Keeping the original per-query connection creation, however, lets connection volume grow unnecessarily and risks reaching MySQL’s maximum connection limit under mobile attendance load.
Solution design
- Replaced per-query connection creation with a keyed registry grouped by tenant and connection class.
- Derived each key from the connection class, host, database name, and username so only the matching context can reuse a connection.
- Reused connections only within their matching group, preserving isolation among default, client, local-client, and core database contexts.
- Centralized database access through the service so connection grouping remains consistent as the attendance flow evolves.
- Reduced connection churn in the mobile-attendance flow, helping keep database usage below the maximum-connection constraint.