Modern applications often have operational data in PostgreSQL and historical or analytical data in a lakehouse. This separation is useful because the two workloads have different requirements, but it also creates a practical problem for developers: business questions often need information from both systems at the same time.

For example, an application may store customers, orders, payments, and inventory in PostgreSQL while storing years of customer activity, application events, clickstream records, and historical transactions in an Iceberg-based lakehouse.

A business user may then ask a question such as:

"Which active customers placed orders recently but have not used the application in the last 30 days?"

The answer may require current customer information from PostgreSQL and historical activity information from the lakehouse.

The challenge is not simply writing a SQL join. The real challenge is deciding where the join should happen, how much data should move between systems, how to filter the lakehouse data before joining it, and whether the query is suitable for an interactive application request.

This article explains practical patterns for joining lakehouse data with operational PostgreSQL data, including query planning, filtering, data movement, performance, security, and production design.

Why Operational and Lakehouse Data Are Separate

PostgreSQL is commonly used for operational workloads.

Typical tables might include:

Code
customers
orders
payments
products
inventory
subscriptions

These tables support application operations such as creating an order, updating a customer profile, checking inventory, and processing payments.

A lakehouse contains a different type of data:

Code
application_events
clickstream
historical_orders
audit_events
device_events
logs
analytics_events

This data can grow very quickly.

A simplified architecture looks like this:

Code
Application
     |
     v
PostgreSQL
     |
     | Data pipeline / CDC
     v
Lakehouse
     |
     v
Iceberg Tables
     |
     v
Object Storage

The operational database remains optimized for application transactions while the lakehouse provides a scalable environment for historical and analytical workloads.

The problem begins when a business query needs both.

A Simple Cross-System Join

Imagine PostgreSQL contains the current customer information:

Code
customers
-------------------------
customer_id
name
status
region
created_at

The lakehouse contains application activity:

Code
customer_events
-------------------------
event_id
customer_id
event_type
event_time
device_type

A business query might need the number of events generated by each active customer.

Conceptually, the query looks like this:

SQL
SELECT
    c.customer_id,
    c.name,
    COUNT(e.event_id) AS event_count
FROM customers c
JOIN customer_events e
    ON e.customer_id = c.customer_id
WHERE c.status = 'Active'
GROUP BY
    c.customer_id,
    c.name;

The SQL looks straightforward.

The architecture behind that SQL is not.

The query may need to move between PostgreSQL and the lakehouse through a federation or query layer. The performance depends on where filtering and aggregation happen, how much data is transferred, and how the query engine executes the join.

Where Should the Join Happen?

This is the first important design question.

There are several possible approaches.

PostgreSQL Performs the Join

The application can retrieve lakehouse data through a foreign table, external table, connector, or another integration mechanism and allow PostgreSQL to participate in the query.

Conceptually:

Code
PostgreSQL
    |
    +---- Current customer data
    |
    +---- External lakehouse data
             |
             v
        Query engine

This can be convenient because application developers can work with familiar SQL.

However, it does not automatically mean that PostgreSQL should process the entire lakehouse dataset.

The Lakehouse Engine Performs the Join

Another option is to send the PostgreSQL data or a filtered subset of it to an analytical engine and perform the join there.

This can be useful when the lakehouse side is much larger and the analytical engine is better suited to large scans and aggregations.

Conceptually:

Code
PostgreSQL
     |
     | Relevant rows
     v
Lakehouse Query Engine
     |
     +---- Iceberg data
     |
     v
Join + Aggregate

A Federation Layer Coordinates the Join

A federation layer can sit between the systems and determine how the query is executed.

Code
                 SQL Query
                     |
                     v
             Federation Layer
               /           \
              /             \
             v               v
       PostgreSQL          Iceberg
             |               |
             v               v
       Operational       Analytical
          Data              Data

The advantage is that the application can have one query interface while the underlying engine handles the data sources.

The important point is that the query planner must still make good decisions. Federation does not magically make large cross-system joins cheap.

Start With the Small Side

One of the most practical rules for cross-system joins is to reduce the amount of data involved before the join.

Suppose PostgreSQL contains 20 million customers and the lakehouse contains 30 billion events.

If the application only needs customers from one region, there is no reason to involve all 20 million customers.

Instead:

Code
20 million customers
        |
        v
Filter region
        |
        v
200,000 customers
        |
        v
Join with lakehouse data

The same principle applies to the lakehouse side.

If the query only needs events from the last seven days, filter those events before joining them with PostgreSQL.

This is one of the most important differences between a query that scales reasonably and one that becomes expensive.

Filter Before the Join

Consider this query:

SQL
SELECT
    c.customer_id,
    c.name,
    COUNT(e.event_id) AS event_count
FROM customers c
JOIN customer_events e
    ON e.customer_id = c.customer_id
WHERE c.status = 'Active'
  AND e.event_time >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY
    c.customer_id,
    c.name;

The business requirement is clear, but the query planner still needs to decide how to execute it.

The ideal logical flow is:

Code
PostgreSQL customers
        |
        v
Active customers
        |
        v
Lakehouse events
        |
        v
Last 30 days
        |
        v
Join
        |
        v
Aggregate

You do not want to process every historical event when only recent events are required.

The exact physical execution depends on the federation or analytical engine, so developers should inspect the query plan rather than assume that filters were pushed to the appropriate system.

Predicate Pushdown Matters

Predicate pushdown means applying filters as close as possible to the data source.

Suppose the lakehouse contains billions of events but the query needs only:

Code
event_time >= last 30 days
event_type = 'purchase'

A good execution strategy pushes these conditions into the lakehouse query.

Instead of:

Code
Read billions of events
        |
        v
Transfer data
        |
        v
Filter purchase events

the goal is closer to:

SQL
Iceberg data
        |
        v
Filter time range
        |
        v
Filter event type
        |
        v
Read required rows
        |
        v
Join

This can reduce both computation and network traffic.

Predicate pushdown is therefore one of the first things to check when a cross-system query becomes slow.

Projection Pushdown Is Also Important

Filtering rows is only one part of reducing data movement.

You should also reduce the number of columns being read.

Avoid:

SQL
SELECT *
FROM customer_events;

If the join only needs three columns, select those columns:

SQL
SELECT
    customer_id,
    event_time,
    event_type
FROM customer_events
WHERE event_time >= CURRENT_DATE - INTERVAL '30 days';

Columnar lakehouse formats are particularly useful here because analytical engines can often read only the columns required by the query.

This becomes increasingly important as the number of columns in an event table grows.

Example: Finding Inactive Customers

Consider a practical requirement:

"Find active customers who have not generated any application activity during the last 30 days."

PostgreSQL contains:

Code
customers
----------------
customer_id
name
status

The lakehouse contains:

Code
customer_events
----------------
customer_id
event_time
event_type

A query can conceptually look like:

SQL
SELECT
    c.customer_id,
    c.name
FROM customers c
LEFT JOIN customer_events e
    ON e.customer_id = c.customer_id
   AND e.event_time >= CURRENT_DATE - INTERVAL '30 days'
WHERE c.status = 'Active'
  AND e.customer_id IS NULL;

The important detail is the placement of the date filter.

It belongs with the lakehouse-side join condition in this example because the business question is whether the customer has a matching event during the specified period.

Moving conditions around without understanding the semantics of LEFT JOIN can change the result.

This is a good example of why cross-system SQL requires both database knowledge and business understanding.

Avoid Joining Raw Event Data When Aggregation Is Enough

Suppose the requirement is:

"Show the number of purchases for each customer."

You do not necessarily need to join every raw event row to PostgreSQL.

The lakehouse side can first aggregate the events:

SQL
SELECT
    customer_id,
    COUNT(*) AS purchase_count
FROM customer_events
WHERE event_type = 'purchase'
  AND event_time >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY customer_id;

The result is much smaller:

Code
customer_id | purchase_count
------------+---------------
101         | 12
102         | 4
103         | 27

That smaller result can then be joined with PostgreSQL customer data.

Conceptually:

Code
Raw Iceberg Events
        |
        v
Filter
        |
        v
Aggregate
        |
        v
Small Result
        |
        v
PostgreSQL Customers
        |
        v
Final Result

This is often a much better design than transferring raw events.

Use Materialized or Pre-Aggregated Data for Repeated Queries

Some queries are executed repeatedly.

For example, a dashboard might display:

Code
Orders today
Orders this month
Active customers
Purchases per customer
Customer activity
Revenue by region

If the same expensive lakehouse calculations are executed every time someone opens the dashboard, response time and compute usage can increase.

A better approach may be to create pre-aggregated analytical datasets.

For example:

Code
Raw Events
    |
    v
Aggregation Pipeline
    |
    v
CustomerDailyMetrics

The dashboard then queries:

Code
CustomerDailyMetrics

instead of scanning billions of raw events.

This moves expensive work from request time to data-processing time.

Joining on Stable Keys

Cross-system joins should use stable identifiers.

For example:

Code
customer_id
order_id
product_id
account_id

The same identifier should have consistent meaning in both systems.

Avoid joining on names:

Code
ON customer.name = event.customer_name

Names can change, contain spelling differences, or fail to be unique.

A stable identifier is much safer:

Code
ON customer.customer_id = event.customer_id

This also makes data pipelines easier to maintain.

Handling Data Type Differences

A cross-system join can fail or become inefficient when the same business identifier uses different data types.

For example:

Code
PostgreSQL:
customer_id BIGINT

Lakehouse:
customer_id STRING

The query may need a conversion:

Code
ON CAST(c.customer_id AS TEXT) = e.customer_id

This may work functionally, but repeated runtime conversions can affect query execution.

A better solution is to standardize the data type in the data pipeline or lakehouse schema.

For example:

Code
PostgreSQL customer_id
        |
        v
Data pipeline
        |
        v
Iceberg customer_id

Both sides should use a consistent logical representation.

Schema consistency is easier to maintain than repeated query-time conversions.

Handling Data Freshness

Operational PostgreSQL data is often updated immediately.

Lakehouse data may arrive through batch pipelines, streaming pipelines, or change data capture.

This creates an important question:

"How current is the lakehouse data?"

Suppose an order was created in PostgreSQL one second ago.

The corresponding event may not yet exist in the Iceberg table.

A cross-system query could therefore return:

Code
PostgreSQL:
Order exists

Lakehouse:
Order event not available yet

This is not necessarily a data error.

It may simply be the expected latency of the data pipeline.

Applications should define freshness requirements clearly.

For real-time operational decisions, PostgreSQL may be the correct source.

For historical analytics, a small ingestion delay may be acceptable.

Handling Deletes and Updates

Operational databases often change existing records.

For example:

Code
Customer status:
Active -> Suspended

The lakehouse may contain historical versions or event records rather than simply replacing the current value.

This creates different semantics.

PostgreSQL may answer:

Code
What is the customer's current status?

The lakehouse may answer:

Code
What was the customer's status when this event occurred?

These are not the same question.

When joining the two systems, developers need to understand whether they are joining current-state data with historical-state data.

For analytical workloads, this distinction is critical.

Handling Slowly Changing Business Data

Consider a customer who changes region.

PostgreSQL may currently show:

Code
customer_id = 101
region = "West"

But historical events may have occurred while the customer belonged to another region.

If the query joins historical events directly with the customer's current region, historical data may be incorrectly attributed to the current region.

This is a common analytical modeling problem.

The solution may involve maintaining historical dimensions or event-time-aware relationships.

Do not assume that current PostgreSQL state is always correct for historical analysis.

Cross-System Joins and Transactions

A normal PostgreSQL transaction can provide transactional guarantees across PostgreSQL operations.

That does not automatically mean the same transaction semantics apply across an external lakehouse system.

For example:

Code
BEGIN
    Update PostgreSQL
    Query Iceberg
    Update PostgreSQL
COMMIT

You should not assume that the entire workflow has one atomic transaction spanning all systems.

If a business operation requires strong transactional guarantees, keep the critical state change inside the transactional system.

Use the lakehouse primarily for analytical access and derived information unless the architecture explicitly provides the required distributed transaction guarantees.

Query Performance and Network Cost

Cross-system joins introduce network boundaries.

A local PostgreSQL join may look like:

Code
PostgreSQL
    |
    v
Table A + Table B
    |
    v
Join

A cross-system join may look like:

Code
PostgreSQL
    |
    v
Network
    |
    v
Lakehouse Query Engine
    |
    v
Object Storage
    |
    v
Network
    |
    v
PostgreSQL

Every additional boundary can introduce latency.

This is why a query that is logically simple can still perform poorly.

Measure:

  • Data scanned.

  • Data transferred.

  • Number of files read.

  • Query execution time.

  • Join cardinality.

  • Rows returned.

  • Network latency.

  • CPU and memory consumption.

  • Query planning time.

Do not optimize only the SQL syntax. Optimize the complete data path.

Caching Can Help Interactive Workloads

If the same cross-system query is executed frequently, caching can reduce repeated work.

For example:

SQL
User Request
     |
     v
Application Cache
     |
     +---- Cache hit -> Return result
     |
     +---- Cache miss
              |
              v
        Cross-system query
              |
              v
        Store result
              |
              v
        Return result

Caching is especially useful for dashboards and summary information that does not need second-level freshness.

The cache duration should match the business requirement.

There is little value in querying a lakehouse every few seconds if the business accepts data that is five minutes old.

Security Considerations

Cross-system queries create additional access paths.

The application or query engine may need access to:

Code
PostgreSQL
Iceberg catalog
Object storage
Metadata
Data files

These permissions should be designed carefully.

Use separate service identities where appropriate.

Grant only the permissions required for the workload.

A reporting service that only reads analytical data should not have permission to modify production PostgreSQL tables or delete object-storage data.

Also consider whether the result of a cross-system query combines sensitive operational information with historical user activity.

Data access controls need to apply to the complete query path, not only to the PostgreSQL database.

Common Mistakes

Joining Entire Tables

Joining complete PostgreSQL and Iceberg datasets without filters can create huge data movement.

Reduce each side before the join whenever possible.

Filtering After the Join

Filtering a massive dataset after combining it wastes work.

Push filters toward the source that owns the data.

Using Current State for Historical Questions

Current customer attributes may not describe the customer's historical state.

Use event-time-aware or historical dimensions when required.

Ignoring Data Freshness

Do not assume that the lakehouse contains the latest PostgreSQL changes.

Understand the ingestion pipeline and its expected delay.

Using Runtime Type Conversions

Joining different data types can create unnecessary query work.

Standardize shared identifiers where possible.

Running Heavy Joins From API Requests

A large analytical query may not belong inside a synchronous API request.

Use caching, pre-aggregation, asynchronous processing, or a reporting workflow when appropriate.

Assuming Distributed Transactions

A cross-system query does not automatically provide one atomic transaction across PostgreSQL and the lakehouse.

Keep transactional operations within the system designed to provide those guarantees.

Best Practices

Keep operational workloads in PostgreSQL.

Use the lakehouse for large historical and analytical datasets.

Filter both sides of a cross-system join before combining them.

Push predicates and column projections toward the source systems.

Aggregate large event datasets before joining them with operational data when possible.

Use stable identifiers instead of names or other mutable values.

Keep shared data types consistent across systems.

Understand the freshness characteristics of the lakehouse pipeline.

Use historical dimensions when current operational state cannot correctly describe historical events.

Avoid heavy cross-system joins inside latency-sensitive APIs.

Cache or pre-aggregate frequently requested analytical results.

Monitor the complete query path rather than PostgreSQL alone.

Apply least-privilege access across PostgreSQL, the lakehouse catalog, and object storage.

Advantages and Disadvantages

Area

Advantages

Disadvantages

Architecture

Keeps operational and analytical workloads separate

Adds cross-system complexity

Data access

Allows business queries to combine current and historical data

Query performance depends on multiple systems

Scalability

Large analytical datasets can remain in the lakehouse

Large joins can become expensive

PostgreSQL

Continues handling transactional workloads

PostgreSQL may still become involved in expensive queries

Analytics

Historical data can be analyzed without copying everything into PostgreSQL

Data freshness may differ from operational data

Maintenance

Each system can be optimized for its own workload

Requires monitoring and maintaining integration points

Flexibility

Supports many reporting and analytical use cases

Requires careful query and data modeling

When Cross-System Joins Are a Good Fit

Joining lakehouse data with operational PostgreSQL data works well when the application needs both current operational state and historical analytical information.

Examples include:

  • Customer activity dashboards.

  • Current customers with historical purchasing behavior.

  • Product usage analysis.

  • Operational reporting with historical context.

  • Customer segmentation.

  • Fraud analysis.

  • Support dashboards combining current account state with historical events.

  • Business reporting that requires current PostgreSQL records and long-term event data.

It is less suitable when the operation requires extremely low latency, strong transactional guarantees across both systems, or repeated scans of very large datasets for every user request.

In those situations, precomputed datasets or a dedicated analytical serving layer may be a better choice.

A Practical Production Architecture

A production system can separate ingestion, storage, and query responsibilities:

SQL
                     Application
                         |
                         v
                +----------------+
                |   PostgreSQL   |
                | Operational DB |
                +--------+-------+
                         |
                         | CDC / Data Pipeline
                         v
                +----------------+
                | Iceberg Tables |
                +--------+-------+
                         |
                         v
                +----------------+
                | Object Storage |
                +----------------+

                         ^
                         |
                Query / Federation
                         |
               +---------+---------+
               |                   |
               v                   v
        PostgreSQL             Lakehouse
        Current Data         Historical Data

The application does not need to own the entire analytical pipeline.

PostgreSQL can remain responsible for operational state.

The data pipeline can move the required information into the lakehouse.

A query or federation layer can then combine the datasets when needed.

For frequently requested results, a separate serving table or cache can provide faster access without executing the full cross-system query every time.

Summary

Joining lakehouse data with operational PostgreSQL data is useful when a business question needs both current application state and large amounts of historical information.

The difficult part is not writing the SQL join. The difficult part is controlling data movement and making sure the join happens at the right stage of the query.

The most important practices are to filter early, select only required columns, reduce large datasets before joining, aggregate raw event data when possible, use stable identifiers, and understand the freshness difference between PostgreSQL and the lakehouse.

Developers should also avoid treating current PostgreSQL state as a substitute for historical state. A customer's current region, status, or profile may not describe what was true when an older event occurred.

Cross-system queries should be designed according to the workload. Small analytical lookups can work well through a federation layer, while large repeated joins may require pre-aggregation, caching, or a dedicated analytical serving model.

When the architecture keeps transactional and analytical responsibilities separate while providing a controlled path between them, PostgreSQL and the lakehouse can work together without forcing either system to handle workloads outside its intended role.