Query Layer Migration from Prisma to Kysely
Authors
Status of This Memo
This document specifies a standards-track architecture for migrating the runtime query layer from Prisma Client to Kysely across backend services. Distribution of this memo is unlimited within the organization and to authorized external reviewers.
This document is a DRAFT and is subject to change based on review feedback.
Abstract
This RFC defines the architecture decision to adopt Kysely as the primary query builder for PostgreSQL database operations, replacing Prisma Client for runtime query generation. The decision is motivated by empirical evidence of non-trivial query-layer overhead in the current Prisma path and by the need for finer control over query composition in a multi-tenant, schema-per-tenant environment.
An initial benchmark on the company list retrieval endpoint measured a 46.9% latency reduction when using Kysely (241 ms) compared to the existing Prisma path (454 ms) under controlled conditions. This RFC codifies the architectural constraints, invariants, and phased migration strategy required to replace Prisma Client while preserving type safety, multi-tenant isolation, and feature parity.
The platform currently uses Prisma Client across 134+ query call sites
spanning 20 tenant-scoped modules in backend-main. Five separate Prisma
generated clients serve three PostgreSQL databases and two MongoDB
databases. This RFC concerns the tenant SQL query path only. Prisma
Migrate and Atlas remain the schema migration tools. MongoDB clients
are unaffected.
Copyright Notice
Copyright (c) 2026 ProficientNow Engineering. All rights reserved.
Changelog
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2026-03-26 | Initial draft |
Scope Boundaries
| Aspect | In Scope | Out of Scope |
|---|---|---|
| Query generation | Runtime query building for tenant SQL read and write operations | Schema migration tooling (Prisma Migrate and Atlas remain) |
| Target client | TenantPrismaClient usage across backend-main modules | AtsPrismaClient, MongoDB clients, and ATS-main queries |
| Multi-tenant access | Schema-scoped query isolation via withSchema() | Tenant provisioning, schema creation, or lifecycle management |
| Performance | Query-layer overhead reduction and latency characteristics | Database engine tuning, index optimization, or query plan fixes |
| Type safety | Compile-time type guarantees for query parameters and results | Runtime validation libraries or request schema contracts |
| Connection pooling | Integration with pg driver pool replacing Prisma internal pool | PgBouncer configuration, pool sizing, or timeout tuning |
| Migration strategy | Phased endpoint-by-endpoint migration with dual-path coexistence | Rewrite scheduling, team assignments, or sprint planning |
| Relation hydration | Reproducing Prisma include behavior via explicit joins and selects | ORM-level lazy loading or virtual relation abstractions |
Intended Audience
This document is written for:
- Backend Engineers working on
backend-mainand tenant-scoped modules - Platform and Infrastructure Engineers responsible for database connectivity
- Architecture and Review Board
- Tech Leads evaluating query-layer decisions
No prior knowledge of Kysely internals is assumed.
Conventions and Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
Table of Contents
Part 1: Foundation
-
- 1.1 Background
- 1.2 Current State
- 1.3 Benchmark Evidence
- 1.4 Motivation
- 1.5 Scope Statement
-
- 2.1 Design Goals
- 2.2 Non-Goals
- 2.3 Invariants
- 2.4 Success Criteria
Part 2: Architecture
-
- 3.1 System Overview
- 3.2 Authority Domains
- 3.3 Trust Boundaries
- 3.4 Stable Interfaces
-
- 4.1 Kysely Query Builder
- 4.2 PostgreSQL Driver and Connection Pool
- 4.3 Schema-Scoped Dialect
- 4.4 Relation Hydration Layer
- 4.5 Prisma Migrate and Atlas (Retained)
- 4.6 Prisma Client (Sunset Path)
Part 3: Migration Strategy
- Migration Strategy
- 5.1 Coexistence Model
- 5.2 Phase 1 — High-Read Endpoints
- 5.3 Phase 2 — Complex Query Endpoints
- 5.4 Phase 3 — Write Operations
- 5.5 Validation Gates
- 5.6 Rollback Mechanics
Part 4: Rationale and Evolution
-
- 6.1 Why This Section Exists
- 6.2 Rejected Alternatives
-
- 7.1 Future Considerations
Appendices
Quick Navigation
| Section | Description | Audience |
|---|---|---|
| 1. Introduction | Problem space and benchmark evidence | All |
| 2. Requirements | Design constraints and invariants | All |
| 3. Architecture | System overview and trust boundaries | Engineers, Architects |
| 4. Components | System building blocks | Engineers |
| 5. Migration Strategy | Phased migration and coexistence | Engineers, Architects |
| 6. Rationale | Rejected alternatives | Architects |
| 7. Evolution | Future considerations | Architects |
Reading Paths
Backend Engineers? Start with Introduction → Requirements → Components → Migration Strategy
Platform / Infra Engineers? Focus on Introduction → Architecture → Components → Glossary
Review Board? Read all sections, especially Requirements (Invariants) → Rationale → Evolution
Understanding Design Decisions? Read Requirements → Rationale → Evolution
