📊 Data Engineering

Data Lakehouse

Data Lakehouse

A combination of a data lake and a data warehouse. ACID + unstructured data.

Detailed Explanation

A Data Lakehouse is a modern data architecture that combines the flexibility and low-cost storage of a Data Lake with the ACID transactions and schema management of a data warehouse. Open table formats such as Delta Lake, Apache Iceberg, and Apache Hudi have made this paradigm possible.

A lakehouse supports BI analytics, machine learning, and real-time streaming all in a single repository, and greatly reduces the data replication costs and ETL complexity that arose when lakes and warehouses were operated separately. Because it uses open formats, it avoids vendor lock-in and can be accessed from a variety of query engines.

Its key features include ACID transactions (preventing concurrent write conflicts), schema evolution (adding/changing columns with no downtime), time travel (querying/rolling back data as of a past point in time), and Z-Ordering (a data layout optimized for query patterns).

Databricks, Snowflake, AWS Lake Formation, Google BigLake, and others provide lakehouse architectures, and unified catalogs such as Unity Catalog or Polaris are used to manage data governance and access control.

Code Example

Python (Delta Lake)
# Delta Lake 기반 레이크하우스 아키텍처
from delta.tables import DeltaTable
from pyspark.sql import SparkSession
from pyspark.sql.functions import *

spark = SparkSession.builder \
    .appName("Lakehouse") \
    .config("spark.sql.extensions",
            "io.delta.sql.DeltaSparkSessionExtension") \
    .config("spark.sql.catalog.spark_catalog",
            "org.apache.spark.sql.delta.catalog.DeltaCatalog") \
    .getOrCreate()

# 1. ACID 트랜잭션으로 데이터 저장
orders_df = spark.read.json("s3://raw/orders/")
orders_df.write \
    .format("delta") \
    .mode("overwrite") \
    .partitionBy("order_date") \
    .save("s3://lakehouse/bronze/orders/")

# 2. 스키마 진화 - 새 컬럼 추가 (무중단)
spark.sql("""
    ALTER TABLE delta.`s3://lakehouse/bronze/orders/`
    ADD COLUMNS (loyalty_points INT)
""")

# 3. Merge (Upsert) 작업 - CDC 처리
delta_orders = DeltaTable.forPath(spark, "s3://lakehouse/bronze/orders/")
updates_df = spark.read.json("s3://raw/orders_updates/")

delta_orders.alias("target").merge(
    updates_df.alias("source"),
    "target.order_id = source.order_id"
).whenMatchedUpdate(set={
    "status": "source.status",
    "updated_at": "source.updated_at"
}).whenNotMatchedInsertAll().execute()

# 4. 타임 트래블 - 과거 시점 조회
historical = spark.read.format("delta") \
    .option("versionAsOf", 5) \
    .load("s3://lakehouse/bronze/orders/")

# 5. Z-Ordering으로 쿼리 최적화
spark.sql("""
    OPTIMIZE delta.`s3://lakehouse/gold/orders/`
    ZORDER BY (customer_id, order_date)
""")

print("Lakehouse operations completed!")

Practical Conversation

We're maintaining both Redshift and an S3 lake, and syncing the data is really hard.
Consider consolidating onto a lakehouse architecture. Applying Delta Lake or Iceberg on top of S3 enables ACID transactions and schema management. Querying directly with Redshift Spectrum or Athena lets you integrate BI and ML without data replication.
What is the difference between Delta Lake and Apache Iceberg?
Both are open table formats that support ACID and time travel. Delta Lake is strongly integrated with the Databricks ecosystem, while Iceberg is vendor-neutral and has excellent support for various engines such as Snowflake, Trino, and Spark. Hudi is specialized for streaming upserts. You can choose based on your organization's environment.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

This Delta table has been running for a year without VACUUM. There are a huge number of version files.
You need to run VACUUM regularly to clean up old version files. The default retention is 7 days, but set a retention period and run it periodically. Also, please compact small files with OPTIMIZE as well. It is effective for reducing S3 costs.

Cautions

  • To prevent the Small Files problem, you must run OPTIMIZE/Compaction regularly.
  • Running long-term without VACUUM causes metadata files to accumulate, leading to performance degradation and increased costs.
  • Compatibility among Delta, Iceberg, and Hudi is not perfect, so review carefully when choosing a format.
  • When using time travel, old version data may be deleted, so check your VACUUM retention settings.
  • Setting table-level access control with Unity Catalog or AWS Lake Formation can strengthen governance and security.

Learn More