C.W.K.
Stream
Lesson 05 of 05 · published

Multi-Tenant Isolation

~20 min · ops, multi-tenant, security

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

세 패턴, 세 risk profile

1. Collection-per-tenant

각 tenant 가 자기 Chroma collection 또는 pgvector 테이블. 가장 강한 isolation; 수천 tenant 면 운영 무거워질 수 있음.

2. Shared collection + tenant_id 메타데이터

한 큰 collection, 모든 청크에 metadata.tenant_id, 모든 query 에 where={tenant_id}. 싸고 수백만 tenant 까지 스케일, 근데 누락된 필터가 tenant 가로질러 leak. 엄격히 테스트.

3. Schema-per-tenant (pgvector)

Postgres schema 로 tenant namespace. Single connection pool, 메타데이터 패턴보다 더 깔끔한 isolation. search_path 로 query 자동 scope.

leak 막는 contract

retrieval 을 tenant_id 파라미터를 요구하는 함수로 감싸. 어떤 코드 path 도 tenant_id 없이 retriever 호출 못 하게. 코드 리뷰가 결국 놓치는 걸 컴파일러가 enforce.

Code

Tenant-required retrieval contract (Python type hints)·python
from typing import NewType

TenantId = NewType('TenantId', str)

def retrieve(question: str, tenant_id: TenantId, k: int = 5):
    return collection.query(
        query_embeddings=[embed(question)],
        n_results=k,
        where={'tenant_id': {'$eq': tenant_id}},
    )
pgvector schema-per-tenant·sql
CREATE SCHEMA acme;
CREATE TABLE acme.chunks (LIKE public.chunks INCLUDING ALL);

-- request 별:
SET search_path = acme, public;
SELECT id, text FROM chunks ORDER BY embedding <=> $1 LIMIT 5;

External links

Exercise

본인 스케일에 맞는 multi-tenant 패턴 골라 (1 — collection-per, 2 — 메타데이터, 3 — schema-per). 구현. cross-tenant leak 테스트 작성. 실행. pass 하면 isolation 작동.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.