Build a serverless transactional data lake with Apache Iceberg, Amazon EMR Serverless, and Amazon Athena
Apache Iceberg changes the operating model of a data lake more than the query syntax. The important design choice here is not simply โserverless Spark plus serverless SQL,โ but the separation of responsibilities across raw, transformed, and business zones while keeping a single governed table format on S3. That means architects still need to decide where ACID semantics are required, which datasets remain append-only, and how much transformation belongs in Spark versus downstream BI access.
The main integration dependency is metadata consistency. Iceberg tables are synchronized with the AWS Glue Data Catalog, so the catalog becomes part of the control plane for schema evolution, snapshot tracking, and cross-engine access. Teams should treat that catalog layer as production infrastructure: permissions, naming discipline, and table lifecycle management matter as much as storage layout. If multiple engines or pipelines touch the same tables, governance and locking choices become operational concerns rather than implementation details.
Serverless removes cluster management, but it does not remove capacity planning. EMR Serverless can start quickly and run Spark jobs without fleet management, yet pre-initialized capacity and executor sizing still affect latency and cost. For transactional ingestion, the trade-off is predictable startup behavior versus paying for warm capacity. For query serving in Athena, the trade-off is convenience versus the need to align table design, file layout, and partition strategy with interactive workloads.
The larger architectural implication is workload convergence. By allowing upserts, reporting, and historical reads over the same Iceberg tables, the platform reduces duplication and reconciliation work. That also raises the bar for data quality, because bad writes, schema drift, or poorly managed compaction can affect every consumer at once. In practice, the value comes from combining serverless elasticity with strong operational controls, not from eliminating those controls.
Apache Iceberg overview
Iceberg is an open-source table format that brings the power of SQL tables to big data files. It enables ACID transactions on tables, allowing for concurrent data ingestion, updates, and queries, all while using familiar SQL. Iceberg employs internal metadata management that keeps track of data and empowers a set of rich features at scale. It allows you to time travel and roll back to old versions of committed data transactions, control the tableโs schema evolution, easily compact data, and employ hidden partitioning for fast queries. Iceberg manages files on behalf of the user and unlocks use cases such as:- Concurrent data ingestion and querying, including streaming and CDC
- BI and reporting with expressive simple SQL
- Empowering ML feature stores and training sets
- Compliance and regulations workloads, such as GDPR find and forget
- Reinstating late-arriving data, which is dimensions data arriving later than the fact data. For example, the reason for a flight delay may arrive well after the fact that the fligh is delayed.
- Tracking data changes and rollback
Build your transactional data lake on AWS
You can build your modern data architecture with a scalable data lake that integrates seamlessly with an Amazon Redshift powered cloud warehouse. Moreover, many customers are looking for an architecture where they can combine the benefits of a data lake and a data warehouse in the same storage location. In the following figure, we show a comprehensive architecture that uses the modern data architecture strategy on AWS to build a fully featured transactional data lake. AWS provides flexibility and a wide breadth of features to ingest data, build AI and ML applications, and run analytics workloads without having to focus on the undifferentiated heavy lifting. Data can be organized into three different zones, as shown in the following figure. The first zone is the raw zone, where data can be captured from the source as is. The transformed zone is an enterprise-wide zone to host cleaned and transformed data in order to serve multiple teams and use cases. Iceberg provides a table format on top of Amazon S3 in this zone to provide ACID transactions, but also to allow seamless file management and provide time travel and rollback capabilities. The business zone stores data specific to business cases and applications aggregated and computed from data in the transformed zone.
One important aspect to a successful data strategy for any organization is data governance. On AWS, you can implement a thorough governance strategy with fine-grained access control to the data lake with AWS Lake Formation.
Serverless architecture overview
In this section, we show you how to ingest and query data in your transactional data lake in a few steps. EMR Serverless is a serverless option that makes it easy for data analysts and engineers to run Spark-based analytics without configuring, managing, and scaling clusters or servers. You can run your Spark applications without having to plan capacity or provision infrastructure, while paying only for your usage. EMR Serverless supports Iceberg natively to create tables and query, merge, and insert data with Spark. In the following architecture diagram, Spark transformation jobs can load data from the raw zone or source, apply the cleaning and transformation logic, and ingest data in the transformed zone on Iceberg tables. Spark code can run instantaneously on an EMR Serverless application, which we demonstrate later in this post. The Iceberg table is synced with the AWS Glue Data Catalog. The Data Catalog provides a central location to govern and keep track of the schema and metadata. With Iceberg, ingestion, update, and querying processes can benefit from atomicity, snapshot isolation, and managing concurrency to keep a consistent view of data. Athena is a serverless, interactive analytics service built on open-source frameworks, supporting open-table and file formats. Athena provides a simplified, flexible way to analyze petabytes of data where it lives. To serve BI and reporting analysis, it allows you to build and run queries on Iceberg tables natively and integrates with a variety of BI tools.Sales data model
Star schema and its variants are very popular for modeling data in data warehouses. They implement one or more fact tables and dimension tables. The fact table stores the main transactional data from the business logic with foreign keys to dimensional tables. Dimension tables hold additional complementary data to enrich the fact table. In this post, we take the example of sales data from the TPC-DS benchmark. We zoom in on a subset of the schema with theweb_sales fact table, as shown in the following figure. It stores numeric values about sales cost, ship cost, tax, and net profit. Additionally, it has foreign keys to dimensional tables like date_dim, time_dim, customer, and item. These dimensional tables store records that give more details. For instance, you can show when a sale took place by which customer for which item.
Dimension-based models have been used extensively to build data warehouses. In the following sections, we show how to implement such a model on top of Iceberg, providing data warehousing features on top of your data lake, and run different workloads in the same location. We provide a complete example of building a serverless architecture with data ingestion using EMR Serverless and Athena using TPC-DS queries.
Prerequisites
For this walkthrough, you should have the following prerequisites:- An AWS account
- Basic knowledge about data management and SQL
Deploy solution resources with AWS CloudFormation
We provide an AWS CloudFormation template to deploy the data lake stack with the following resources:- Two S3 buckets: one for scripts and query results, and one for the data lake storage
- An Athena workgroup
- An EMR Serverless application
- An AWS Glue database and tables on external public S3 buckets of TPC-DS data
- An AWS Glue database for the data lake
- An AWS Identity and Access Management (IAM) role and polices
- Launch the CloudFormation stack:
- Keep the template settings as is.
- Check the I acknowledge that AWS CloudFormation might create IAM resources box.
- Choose Submit
Upload Spark scripts to Amazon S3
Complete the following steps to upload your Spark scripts:- Download the following scripts: ingest-iceberg.py and update-item.py.
- On the Amazon S3 console, go to the
datalake-resources-<AccountID>-us-east-1bucket you created earlier. - Create a new folder named
scripts. - Upload the two PySpark scripts:
ingest-iceberg.pyandupdate-item.py.
Create Iceberg tables and ingest TPC-DS data
To create your Iceberg tables and ingest the data, complete the following steps:- On the Amazon EMR console, choose EMR Serverless in the navigation pane.
- Choose Manage applications.
- Choose the application
datalake-app.
- Choose Start application.
job ingest-iceberg.py. The job creates the Iceberg tables and then loads data from the previously created AWS Glue Data Catalog tables on TPC-DS data in an external bucket.
- Navigate to the
datalake-app. - On the Job runs tab, choose Submit job.
- For Name, enter
ingest-data. - For Runtime role, choose the IAM role created by the CloudFormation stack.
- For Script location, enter the S3 path for your resource bucket (
datalake-resource-<####>-us-east-1>scripts>ingest-iceberg.py).
- Under Spark properties, choose Edit in text.
- Enter the following properties, replacing <BUCKET_NAME> with your data lake bucket name
datalake-<####>-us-east-1(not datalake-resources)
--conf spark.executor.cores=2 --conf spark.executor.memory=4g --conf spark.driver.cores=2 --conf spark.driver.memory=8g --conf spark.executor.instances=2 --conf spark.jars=/usr/share/aws/iceberg/lib/iceberg-spark3-runtime.jar --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions --conf spark.sql.catalog.dev.warehouse=s3://<BUCKET_NAME>/warehouse --conf spark.sql.catalog.dev=org.apache.iceberg.spark.SparkCatalog --conf spark.sql.catalog.dev.catalog-impl=org.apache.iceberg.aws.glue.GlueCatalog --conf spark.sql.catalog.glue_catalog.lock-impl=org.apache.iceberg.aws.glue.DynamoLockManager --conf spark.sql.catalog.glue_catalog.lock.table=myIcebergLockTab --conf spark.dynamicAllocation.maxExecutors=8 --conf spark.driver.maxResultSize=1G --conf spark.hadoop.hive.metastore.client.factory.class=com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Submit the job.
Query Iceberg tables
In this section, we provide examples of data warehouse queries from TPC-DS on the Iceberg tables.- On the Athena console, open the query editor.
- For Workgroup, switch to
DatalakeWorkgroup.
- Choose Acknowledge.
DatalakeWorkgroup will run on Athena engine version 3.
- On the Saved queries tab, choose a query to run on your Iceberg tables.
- Query3 โ Report the total extended sales price per item brand of a specific manufacturer for all sales in a specific month of the year.
- Query45 โ Report the total web sales for customers in specific zip codes, cities, counties, or states, or specific items for a given year and quarter.
- Query52 โ Report the total of extended sales price for all items of a specific brand in a specific year and month.
- Query6 โ List all the states with at least 10 customers who during a given month bought items with the price tag at least 20% higher than the average price of items in the same category.
- Query75 โ For 2 consecutive years, track the sales of items by brand, class, and category.
- Query86a โ Roll up the web sales for a given year by category and class, and rank the sales among peers within the parent. For each group, compute the sum of sales and location with the hierarchy and rank within the group.
Query3.
- Before you run the query, confirm that Database is set to
datalake.
- Now you can run the query.
- Repeat these steps to run the other queries.
Update the item table
After running the queries, we prepare a batch of updates and inserts of records into theitem table.
- First, run the following query to count the number of records in the
itemIceberg table:
SELECT count(*) FROM "datalake"."item_iceberg";
- Select item records with a price higher than $90:
SELECT count(*) FROM "datalake"."item_iceberg" WHERE i_current_price > 90.0;
update-item.py job takes these 1,112 records, modifies 11 records to change the name of the brand to Unknown, and changes the remaining 1,101 recordsโ i_item_id key to flag them as new records. As a result, a batch of 11 updates and 1,101 inserts are merged into the item_iceberg table.
The 11 records to be updated are those with price higher than $90, and the brand name starts with corpnameless.
- Run the following query:
SELECT count(*) FROM "datalake"."item_iceberg" WHERE i_current_price > 90.0 AND i_brand LIKE 'corpnameless%';
item_update.py job replaces the brand name with Unknown and merges the batch into the Iceberg table.
Now you can return to the EMR Serverless console and run the job on the EMR Serverless application.
- On the application details page, choose Submit job.
- For Name, enter
update-item-job. - For Runtime roleยธ use the same role that you used previously.
- For S3 URI, enter the
update-item.pyscript location.
- Under Spark properties, choose Edit in text.
- Enter the following properties, replacing the <BUCKET-NAME> with your own
datalake-<####>-us-east-1:
--conf spark.executor.cores=2 --conf spark.executor.memory=8g --conf spark.driver.cores=4 --conf spark.driver.memory=8g --conf spark.executor.instances=2 --conf spark.jars=/usr/share/aws/iceberg/lib/iceberg-spark3-runtime.jar --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions --conf spark.sql.catalog.dev=org.apache.iceberg.spark.SparkCatalog --conf spark.sql.catalog.dev.catalog-impl=org.apache.iceberg.aws.glue.GlueCatalog --conf spark.sql.catalog.glue_catalog.lock-impl=org.apache.iceberg.aws.glue.DynamoLockManager --conf spark.sql.catalog.glue_catalog.lock.table=myIcebergLockTab --conf spark.dynamicAllocation.maxExecutors=4 --conf spark.driver.maxResultSize=1G --conf spark.sql.catalog.dev.warehouse=s3://<BUCKET-NAME>/warehouse --conf spark.hadoop.hive.metastore.client.factory.class=com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Then submit the job.
- After the job finishes successfully, return to the Athena console and run the following query:
SELECT count(*) FROM "datalake"."item_iceberg";
Time travel
To run a time travel query, complete the following steps:- Get the timestamp of the job run via the application details page on the EMR Serverless console, or the Spark UI on the History Server, as shown in the following screenshot.
- Convert the timestamp from the format
YYYY/MM/DD hh:mm:ss to YYYY-MM-DDThh:mm:ss.sTZDwith time zone. For example, from2023/02/20 14:40:41to2023-02-20 14:40:41.000 UTC. - On the Athena console, run the following query to count the
itemtable records at a time before the update job, replacing <TRAVEL_TIME> with your time:
SELECT count(*) FROM "datalake"."item_iceberg" FOR TIMESTAMP AS OF TIMESTAMP <TRAVEL_TIME>;
- Now you can run a query with a timestamp after the successful run of the update job (for example,
2023-02-20 15:06:00.000 UTC):
SELECT count(*) FROM "datalake"."item_iceberg" FOR TIMESTAMP AS OF TIMESTAMP <TRAVEL_TIME>;
Clean up
Complete the following steps to clean up your resources:- On the Amazon S3 console, empty your buckets.
- On the Athena console, delete the workgroup
DatalakeWorkgroup. - On the EMR Studio console, stop the application
datalake-app. - On the AWS CloudFormation console, delete the CloudFormation stack.
Conclusion
In this post, we created a serverless transactional data lake with Iceberg tables, EMR Serverless, and Athena. We used TPC-DS sales data with 10 GB data and more than 7 million records in the fact table. We demonstrated how straightforward it is to rely on SQL and Spark to run serverless jobs for data ingestion and upserts. Moreover, we showed how to run complex BI queries directly on Iceberg tables from Athena for reporting. You can start building your serverless transactional data lake on AWS today, and dive deep into the features and optimizations Iceberg provides to build analytics applications more easily. Iceberg can also help you in the future to improve performance and reduce costs.About the Author
Houssem is a Specialist Solutions Architect at AWS with a focus on analytics. He is passionate about data and emerging technologies in analytics. He holds a PhD on data management in the cloud. Prior to joining AWS, he worked on several big data projects and published several research papers in international conferences and venues.Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
