
π Built a Cross-Database(AI) Recommendation System using FDW + Prisma
Recently worked on an interesting backend problem β sharing the approach in case it helps others working with multi-DB systems π π§© Problem We had two separate databases: Core DB β transactional data (activities, participants, items) Profile DB β user/entity master data + metadata We needed: π A unified dataset for ranking/recommendation π Without duplicating data across databases π‘ Solution: PostgreSQL FDW Used Foreign Data Wrapper (FDW) to query Profile DB directly from Core DB. CREATE EXTENSION postgres_fdw ; CREATE SERVER remote_profile_srv FOREIGN DATA WRAPPER postgres_fdw OPTIONS ( host 'host' , dbname 'profile_db' , port '5432' ); π Foreign Tables Mapped remote tables into local DB: fdw_schema.entities fdw_schema.entity_details fdw_schema.entity_context π Important: Convert enums β text to avoid cross-DB type issues. π§ Data Layer Design Built 4 layered views: 1οΈβ£ entity_profile_view Entity + metadata + classifications Handles JSON structures (like category mappings) 2οΈβ£ activity_
Continue reading on Dev.to
Opens in a new tab



.jpg&w=1200&q=75)
