Skip to content
TeachTrails
Data EngineeringAzure

Azure Data Lake Storage Gen2 Tutorial: Containers, Folders, Tiers and Python

Learn ADLS Gen2 and Blob Storage: storage accounts, hierarchical namespace, containers, lake folder layout, access tiers, redundancy, and Python code we ran on Azurite.

Sukanya Saha, Technology Consultant

13 min read

Beginner friendly

Storage accounts, containers, files

LevelExampleNotes
Storage accountstshopkartdevGlobally unique name, 3–24 lowercase letters/numbers; region, redundancy, HNS on/off
Container (file system)lakeTop-level folder; access can be set here
Directories + filesraw/orders/2026/10/01/orders_2026-10-01.csvReal directories only with HNS (ADLS Gen2)
🗂️ A common lake layout
lake/
├── raw/            data exactly as it arrived (bronze)
│   └── orders/2026/10/01/orders_2026-10-01.csv
├── curated/        cleaned, typed, de-duplicated (silver/gold)
│   └── daily_revenue/daily_revenue.parquet
└── archive/        old raw data on a cool tier

Try it locally with Azurite

Azurite is Microsoft's official Azure Storage emulator. The Python code is the same you'd use against Azure; only the connection string changes.

Terminal
$npm install azurite && npx azurite-blob --location ./azurite-data
$pip install azure-storage-blob pandas pyarrow
Python
from azure.storage.blob import BlobServiceClient

# Azurite's well-known local development account (published by Microsoft; never use it in Azure)
CONN = ("DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;"
        "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;"
        "BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;")
service = BlobServiceClient.from_connection_string(CONN)
lake = service.create_container("lake")
print("container:", lake.container_name)
Output
container: lake

Upload into dated folders

Python
import glob, os

for path in sorted(glob.glob("../pyspark/data/orders/orders_2026-10-0[1-3].csv")):
    day = os.path.basename(path)[7:17]                         # 2026-10-01
    blob_name = f"raw/orders/{day.replace('-', '/')}/{os.path.basename(path)}"
    with open(path, "rb") as f:
        lake.upload_blob(blob_name, f, overwrite=True,
                         metadata={"source": "shopkart-app", "load_date": day})
    print("uploaded", blob_name)
Output
uploaded raw/orders/2026/10/01/orders_2026-10-01.csv
uploaded raw/orders/2026/10/02/orders_2026-10-02.csv
uploaded raw/orders/2026/10/03/orders_2026-10-03.csv
Python
# Blob storage is flat: "folders" are just prefixes in the name
for b in lake.list_blobs(name_starts_with="raw/orders/2026/10/"):
    print(f"{b.name:<45} {b.size:>6} bytes  tier={b.blob_tier}")

print([p.name for p in lake.walk_blobs(name_starts_with="raw/orders/2026/10/", delimiter="/")])
Output
raw/orders/2026/10/01/orders_2026-10-01.csv     4548 bytes  tier=Hot
raw/orders/2026/10/02/orders_2026-10-02.csv     5402 bytes  tier=Hot
raw/orders/2026/10/03/orders_2026-10-03.csv     4226 bytes  tier=Hot
['raw/orders/2026/10/01/', 'raw/orders/2026/10/02/', 'raw/orders/2026/10/03/']

In Blob storage those “folders” are just prefixes in each blob's name; walk_blobs with a / delimiter groups them. With ADLS Gen2 they're real directories, which is why renaming or deleting a folder is one fast operation there instead of copying every file.

Python
props = lake.get_blob_client("raw/orders/2026/10/01/orders_2026-10-01.csv").get_blob_properties()
print(props.metadata, props.content_settings.content_type, props.etag)
Output
{'source': 'shopkart-app', 'load_date': '2026-10-01'} application/octet-stream "0x264614E5C431A80"

Metadata travels with each file (useful for lineage). Note the content type defaulted to application/octet-stream: pass ContentSettings(content_type="text/csv") when it matters.

Read, transform, write Parquet

Python
import io, pandas as pd

frames = []
for b in lake.list_blobs(name_starts_with="raw/orders/"):
    data = lake.download_blob(b.name).readall()
    frames.append(pd.read_csv(io.BytesIO(data)))
orders = pd.concat(frames)
delivered = orders[orders.status == "DELIVERED"]
summary = (delivered.assign(day=delivered.order_ts.str[:10],
                            amount=delivered.quantity * delivered.unit_price)
           .groupby("day").agg(orders=("order_id", "count"), revenue=("amount", "sum")).reset_index())
print(summary)

buf = io.BytesIO(); summary.to_parquet(buf, index=False)
lake.upload_blob("curated/daily_revenue/daily_revenue.parquet", buf.getvalue(), overwrite=True)
print("wrote curated/daily_revenue/daily_revenue.parquet,", len(buf.getvalue()), "bytes")
Output
          day  orders  revenue
0  2026-10-01      60   161518
1  2026-10-02      75   150211
2  2026-10-03      65   137518
wrote curated/daily_revenue/daily_revenue.parquet, 2299 bytes

Same daily totals as our PySpark streaming lesson. Small files are fine with pandas; for gigabytes you'd read the same paths with Spark (abfss://[email protected]/raw/orders/) on Databricks or Fabric.

Access tiers and redundancy

Python
blob = lake.get_blob_client("raw/orders/2026/10/01/orders_2026-10-01.csv")
blob.set_standard_blob_tier("Cool")                       # older raw files: cheaper storage
print(blob.get_blob_properties().blob_tier)
Output
Cool
TierStorage costRead costUse for
HotHighestLowestRecent and frequently used data
CoolLowerHigherOlder raw files (30+ days minimum)
ColdLower stillHigher stillRarely read (90+ days minimum)
ArchiveLowestHighest; offline, hours to rehydrateCompliance copies (180+ days)
RedundancyCopiesProtects against
LRS3 in one datacenterDisk/server failure (cheapest, dev)
ZRS3 across availability zonesA datacenter outage (common for prod)
GRS / GZRSPlus a copy in a paired regionA whole region outage

The ADLS Gen2 API (on real Azure)

Azurite doesn't emulate the dfs endpoint, so this part follows Microsoft's SDK documentation:

Python · not run (needs Azure)
# Real ADLS Gen2 (not run here: needs an Azure storage account and an Entra ID sign-in)
from azure.identity import DefaultAzureCredential
from azure.storage.filedatalake import DataLakeServiceClient

lake = DataLakeServiceClient("https://stshopkartdev.dfs.core.windows.net",
                             credential=DefaultAzureCredential())   # no keys: your identity (lesson 3)
fs = lake.get_file_system_client("lake")
fs.get_directory_client("raw/orders/2026/10").rename_directory("lake/archive/orders/2026/10")  # one fast, atomic call

🎯 Interview questions on this topic

Try to answer out loud first, then tap to check.

Q1What is the difference between Blob Storage and ADLS Gen2?Fresher
ADLS Gen2 is Blob Storage with the hierarchical namespace enabled: true directories with atomic rename/delete, POSIX ACLs, and the dfs endpoint optimized for analytics engines, at blob storage pricing.
Q2How do you organise a data lake?1–3 yrs
Zones such as raw/bronze, curated/silver, gold/serving, plus archive; folders by source and date (yyyy/MM/dd) for partition pruning; consistent naming; containers or folders aligned with access boundaries; lifecycle rules for tiering.
Q3How do you reduce storage costs?1–3 yrs
Lifecycle management to move older data to cool/cold/archive, compress and use Parquet, delete temporary data, avoid many tiny files, choose redundancy per environment, and monitor transactions and egress.
Q4Why does hierarchical namespace matter for Spark jobs?3+ yrs
Spark commit protocols write to temporary folders then rename them. With a flat namespace a 'folder rename' copies and deletes every object (slow, not atomic); with HNS it's a single metadata operation, making jobs faster and safer.

Key takeaways

  • Turn on hierarchical namespace for any data lake.
  • Lay out folders by zone, source and date.
  • Tiers and redundancy are your main cost levers.
  • Azurite lets you practise storage code for free.

Frequently asked questions

What is ADLS Gen2?

Azure Data Lake Storage Gen2 is Azure Blob Storage with the hierarchical namespace turned on. You get real directories (fast, atomic renames and deletes), POSIX-style ACLs on folders and files, and the dfs endpoint that Spark and Databricks use with abfss:// paths, while keeping blob storage prices and tiers.

Blob storage or ADLS Gen2 for a data lake?

ADLS Gen2. Analytics engines rename and delete whole folders constantly (for example when a Spark job commits output); with a flat namespace that means copying every file. Turn on hierarchical namespace when you create the account; it can't simply be switched back off.

What is Azurite?

Microsoft's free, open-source emulator for Azure Storage (Blob, Queue, Table) that runs on your laptop. Code written with the Azure SDK works against it with a connection string change. It doesn't emulate the ADLS Gen2 dfs endpoint.

Which access tier should I use?

Hot for data read often (recent raw and curated data), Cool for data read rarely (older raw files, 30+ days), Cold for very rarely read (90+ days), Archive for compliance copies you almost never need (hours to rehydrate). Lifecycle management rules move files automatically by age.

🧠 Quick check: ADLS Gen2

  1. 1. What makes a storage account an ADLS Gen2 data lake?

  2. 2. In plain Blob storage, 'raw/orders/2026/10/' is...

  3. 3. Old raw files are read once a quarter. Tier?

  4. 4. Spark reads ADLS Gen2 with paths like...

Azure Cloud for Data Engineers

Part 2 of 10: Azure Data Lake Storage Gen2 Tutorial