📊 Data Engineering

Data Lake

Data Lake

A central repository for storing raw data. Schema-on-read.

Detailed Explanation

A Data Lake is a centralized repository that stores structured, semi-structured, and unstructured data in its raw form. Unlike the traditional data warehouse's 'Schema on Write', a data lake uses a 'Schema on Read' approach, applying the schema at read time rather than at the time the data is stored.

Object storage such as Amazon S3, Azure Data Lake Storage, and Google Cloud Storage is the underlying technology, and petabyte-scale data can be stored at low cost. Using columnar formats such as Parquet, ORC, and Avro can significantly improve query performance and compression efficiency.

A data lake is generally managed in a layered structure (Zones). Raw data is ingested into the Raw Zone, and then refined and processed as it passes through the Bronze/Silver/Gold Zones. Table schemas and partition information are managed with AWS Glue Catalog or Hive Metastore.

It is used in a variety of use cases such as preparing AI/ML training data, log analysis, and collecting IoT sensor data, and large volumes of data are processed in parallel with distributed processing engines such as Spark, Presto, and Trino.

Code Example

Python (PySpark + AWS)
# AWS S3 기반 데이터 레이크 아키텍처
from pyspark.sql import SparkSession
from pyspark.sql.functions import *
import boto3

# S3 데이터 레이크 계층 구조
DATA_LAKE = "s3://company-datalake"
ZONES = {
    "raw": f"{DATA_LAKE}/raw/",      # 원시 데이터
    "bronze": f"{DATA_LAKE}/bronze/", # 정제된 데이터
    "silver": f"{DATA_LAKE}/silver/", # 변환/집계 데이터
    "gold": f"{DATA_LAKE}/gold/"      # 분석용 마트
}

# Spark 세션 초기화
spark = SparkSession.builder \
    .appName("DataLakeProcessing") \
    .config("spark.sql.extensions",
            "io.delta.sql.DeltaSparkSessionExtension") \
    .getOrCreate()

# Raw Zone: 원시 JSON 데이터 수집
raw_events = spark.read \
    .option("multiLine", True) \
    .json(f"{ZONES['raw']}/events/2024/01/15/")

# Bronze Zone: 정제 및 파티셔닝
bronze_events = raw_events \
    .dropDuplicates(["event_id"]) \
    .withColumn("event_date", to_date("timestamp")) \
    .withColumn("event_hour", hour("timestamp"))

bronze_events.write \
    .partitionBy("event_date", "event_hour") \
    .mode("append") \
    .parquet(f"{ZONES['bronze']}/events/")

print(f"Processed {bronze_events.count()} events to Bronze Zone")

# AWS Glue Catalog에 테이블 등록
glue = boto3.client('glue')
glue.create_table(
    DatabaseName='bronze_db',
    TableInput={
        'Name': 'events',
        'StorageDescriptor': {
            'Location': f"{ZONES['bronze']}/events/",
            'InputFormat': 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
        }
    }
)

Practical Conversation

Data keeps piling up in the data lake, but nobody knows what is where. It feels like it has turned into a data swamp.
Introducing a data catalog is urgent. Manage metadata with AWS Glue Catalog or DataHub, and clearly define the Bronze/Silver/Gold layer structure to distinguish data maturity levels. A lake without governance becomes a swamp.
What is the difference between a data lake and a data warehouse?
A lake stores raw data with Schema on Read and applies the schema when the data is read. A warehouse refines data before storing it with Schema on Write. A lake is flexible but lacks ACID, while a warehouse is structured but costs more. A lakehouse is an architecture that combines the two.

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

You're storing Parquet files in S3, but you're writing them flat without partitions.
Please partition by date or a frequently filtered column. For example: partitionBy("event_date"). Partition pruning can reduce the amount of data scanned per query by more than 90%. An appropriate file size is 128MB to 1GB.

Cautions

  • Accumulating data without metadata management turns it into a 'Data Swamp'. A catalog is essential.
  • Since it does not support ACID transactions by default, consider adopting Delta Lake or Iceberg.
  • Having many small files (Small Files) sharply degrades query performance. Run Compaction jobs regularly.
  • Without management of access permissions and data classification (PII, sensitive information), the risk of security incidents is high.
  • When choosing a partition key, if the cardinality is too high (e.g., user_id), partition explosion occurs. Apply date-based partitions first.

Learn More