Menu

One Kernel for Every Tenant: FrankenPHP Worker Mode for Database-per-Tenant Symfony 8.1
📰

One Kernel for Every Tenant: FrankenPHP Worker Mode for Database-per-Tenant Symfony 8.1

DEV Community: php·Matt Mochalkin·about 12 hours ago
#c5hWKBLW
#devto#dev#tenant#worker#connection
Reading 0:00
15s threshold

In part 1 we put every free tenant of a database-per-tenant SaaS on one shared Symfony 8.1 deployment. Each request names its tenant in the path, a DBAL wrapper reconnects to the tenant's database, a cache decorator namespaces by tenant, and one Messenger worker reads every tenant's stream. The saving was memory: one set of processes per placement instead of one per tenant.

The HTTP side of that deployment still ran under php-fpm, and php-fpm forgets everything between requests. Every request boots the kernel, loads the compiled container, asks Redis whether the tenant is placed here, and opens a connection to the tenant's database. Part 1 measured that last step at about six milliseconds per switch and shrugged, because a php-fpm request pays a connection anyway. This article is about that shrug.

FrankenPHP's worker mode keeps the kernel alive across requests. For a single-tenant app that is a throughput story.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.