Data Lake
Data Lake
A central repository for storing raw data. Schema-on-read.
Data Lake
A central repository for storing raw data. Schema-on-read.
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.
# 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'
}
}
)
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free