๐ 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 d...

Source: DEV Community
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๏ธโฃ acti