---
# Improving data processing with Spark 3.0 & Delta Lake

**URL:** https://www.sigmoid.com/blogs/improving-data-processing-with-spark-3-0-delta-lake/
Date: 2021-07-20
Author: Sigmoid
Post Type: post
Summary: Collecting, processing, and carrying out analysis on streaming data, in industries such as ad-tech involves intense data engineering. The data generated daily...Read More...
Categories: Data Management
Tags: Cloud Transformation
Featured Image: https://www.sigmoid.com/wp-content/uploads/2023/10/Improving-Data-Processing-with-Spark-3.0-Delta-Lake-banner-opt.jpg
---

Collecting, processing, and carrying out analysis on streaming data, in industries such as ad-tech involves intense data engineering. The data generated daily is huge (100s of GB data) and requires a significant processing time to process the data for subsequent steps.

 
Another challenge is the joining of datasets to derive insights. Each process on average has more than 10 datasets and an equal number of joins with multiple keys. The partition size for each key is unpredictable on each run.

 
And, finally, if the amount of data exceeds on certain occasions, the storage may run out of memory. This means that the process would die in the middle of the final writes, making consumers distinctly read the input data frames.

 
In this blog, we will cover an overview of [Delta Lakes](/blogs/near-real-time-finance-data-warehousing-using-apache-spark-and-delta-lake/), its advantages, and how the above challenges can be overcome by moving to Delta Lake and migrating to Spark 3.0 from Spark 2.4.

## What is Delta Lake?

Developed at Databricks, “Delta Lake is an open-source data storage layer that runs on the existing Data Lake and is fully cooperative with [Apache Spark](/blogs/apache-spark-for-real-time-analytics/") APIs. Along with the ability to implement ACID transactions and scalable metadata handling, Delta Lakes can also unify the streaming and batch data processing”.

Source: [Databricks](https://docs.databricks.com/delta/index.html#:~:text=Delta%20Lake%20is%20an%20open,compatible%20with%20Apache%20Spark%20APIs.)

 
Delta Lake uses versioned Parquet files to store data in the cloud. Once the cloud location is configured, Delta Lake tracks all the changes made to the table or blob store directory to provide ACID transactions.

## Advantages of using Delta Lakes

Delta lake allows thousands of data to run in parallel, address optimization and partition challenges, faster metadata operations, maintains a transactional log and continuously keeps updating the data. Below we discuss a few major advantages:

 
Delta Lake Transaction Log

 
Delta lake transaction logs are an append-only file and contain an ordered record of all transactions performed on the Delta Lake table. The transaction log allows various users to read and write to the given table in parallel. It acts as a single source of truth or the central repository that logs all changes made to the table by the user. It maintains atomicity and continuously watches the transactions performed on Delta Lake.

 
As mentioned above, [Spark](/blogs/getting-data-into-spark-streaming/) checks the delta log for any new transactions, following which Delta Lake ensures that the user’s version is always in sync with the master record. It also ensures that no conflicting changes are being made to the table. If the process crashes before updating the delta log, the files will not be available to any reading processes as the reads always go through the transaction log.

 
Transaction Log Working and Atomic Commits

 
Delta lake does a checkpoint on every ten commits. The checkpointed file contains the current state of the data in the Parquet format which can be read quickly. When multiple users try to modify the table at the same time, Delta Lake resolves the conflicts using optimistic concurrency control.

 
The schema of the metadata is as follows:

 

Column
Type
Description

format
string
Format of the table, that is, “delta”.

id
string
Unique ID of the table

name
string
Name of the table as defined in the metastore

description
string
Description of the table.

location
string
Location of the table.

createdAt
timestamp
When the table was created

partitionColumns
array of strings
Names of the partition columns if the table is
partitioned

numFiles
long
Number of the files in the latest version of the table

properties
String-string map
All properties set for this table

minReaderVersion
int
Minimum version of readers (according to the log
protocol) that can read the table.

minWriterVersion
int
Minimum version of readers (according to the log
protocol) that can write to the table.

Source: [GitHub](https://github.com/delta-io/delta/blob/master/PROTOCOL.md)

 
Add and Remove File

 
Whenever a file is added or an existing file is removed, these actions are logged. The file path is unique and is considered as the primary key for the set of files inside it. When a new file is added on a path that is already present in the table, statistics and other metadata on the path are updated from the previous version. Similarly, remove action is indicated by timestamp. A remove action remains in the table as a tombstone until it has expired. A tombstone expires when the TTL (Time-To-Live) exceeds.

 
Since actions within a given Delta file are not guaranteed to be applied in order, it is not valid for multiple file operations with the same path to exist in a single version.

 
The dataChange flag on either an ‘add’ or ‘remove’ can be set to false to minimize the concurrent operations conflicts.

 
The schema of the add action is as follows:

Field Name
Data Type
Description

path
String
A relative path, from the root of the table, to a file
that should be added to the table

partitionValues
Map[String,String]
A map from partition column to value for this file.

size
Long
The size of this file in bytes

modificationTime
Long
The time this file was created, as milliseconds since
the epoch

dataChange
Boolean
When false the file must already be present in the
table or the records in the added file must be
contained in one or more remove actions in the same
version

stats
Statistics Struct
Contains statistics (e.g., count, min/max values for
columns) about the data in this file

tags
Map[String,String]
Map containing metadata about this file

 
The schema of the remove action is as follows:

 
deletionTimestamplongThe time the deletion occurred, represented as
milliseconds since the epochdataChangeBooleanWhen false the records in the removed file must be
contained in one or more add file actions in the same
versionextendedFileMetadataBooleanWhen true the fields partitionValues, size, and tags
are presentpartitionValuesMap[String, String]A map from partition column to value for this file. See
also Partition Value SerializationsizeLongThe size of this file in bytestagsMap[String, String]Map containing metadata about this file

Field Name
Data Type
Description

path
string
An absolute or relative path to a file that should be
removed from the table

Source: [GitHub](https://github.com/delta-io/delta/blob/master/PROTOCOL.md)

 
The schema of the metadata contains the file path on each add/remove action and the [Spark](/blogs/spark-streaming-internals/) read process does not need to do a full scan to get the file listings.

 
If a write fails without updating the transaction log, since the consumer’s reading will always go through the metadata, those files will be ignored.

## Advantages of migrating to Spark 3.0

Apart from leveraging the benefits of Delta Lake, migrating to Spark 3.0 improved data processing in the following ways:

 
Skewed Join Optimization

 
Data skew is a condition in which a table’s data is unevenly distributed among partitions in the cluster and can severely downgrade the performance of queries, especially those with joins. Skewness can lead to extreme imbalance in the cluster thereby increasing the data processing time.

 
The data skew condition can be handled mainly by three approaches.

 

 	- Using the configuration “spark.sql.shuffle.partitions” for increased parallelism on more evenly distributed data.

 	- Increasing the broadcast hash join threshold using the configuration spark.sql.autoBroadcastJoinThreshold to the maximum size in bytes for the table that has to be broadcasted to all worker nodes during performing a join.

 	- Key Salting (Add prefix to the skewed keys to make the same key different and then adjust the data distribution).

Spark 3.0 has added an [optimization](/blogs/campaign-optimization-cpg/) to auto handling skew join based on the runtime statistics with the new adaptive execution framework.

 
Skewed Partition Condition

 
The challenge of skewed partitions that existed in the previous version of the Spark 2.4 had a huge impact on the network time and execution time of a particular task. Moreover, the methods to deal with it were mostly manual. Spark 3.0 overcomes these challenges.

 
The skewed partition will have an impact on the network traffic and on the task execution time, since this particular task will have much more data to process.

 
The skewed join partition is calculated by the data size and row counts from the runtime map statistics.

 
Optimization

 
![](/wp-content/uploads/2022/12/sigmoid-blog-delta-lake-opti.jpg)
 
Adapted from: [Apache Spark Jira](https://docs.google.com/document/d/1NkXN-ck8jUOS0COz3f8LUW5xzF8j9HFjoZXWGGX2HAg/edit#heading=h.60dh8l6nvck)

 
From the above table, the Dataframe Campaigns joins with the Dataframe Organizations. One of the partitions (Partition 0) from Organizations is big and skewed. Partition 0 is the result of 9 maps from the previous stage(Map-0 to Map-8). Spark’s OptimizeSkewedJoin rule will split the Partition into 3 and then create 3 separate tasks each one being a partial partition from Partition 0 (Map-0 to Map-2, Map-3 to Map-5, and Map-6 to Map-9) and joins with the Campaigns Partition 0. This approach results in additional cost by reading Partition 0 of table Campaigns equal to the number of partial partitions from the table Organizations.

## End Result

Using Delta Lake and Spark 3.0, we enabled the following results for the ad tech firm:

 

 	- The time of data processing was reduced from 15 hours to 5-6 hours

 	- 50% reduction in AWS EMR cost

 	- Preventing loss of data and death of processes which was a frequent occurrence when the system went out of memory or the processing stopped due to a glitch in the system

 	- Monitoring & Alerting features were installed to notify in case the process fails

 	- Complete orchestration using Airflow to achieve full automation and dependency management between processes

## Author

Rahul Radhakrishnan is a Technical Lead in the Data Engineering team at Sigmoid. He has 14 years of experience in the Software Industry with expertise on Big-Data technologies, back-end server-side development and applications development. He has worked in various domains like multimedia, Ecommerce, Network Security and Digital Marketing.

[lc_the_tags]

## Featured blogs

[lc_get_posts post_type="post"
posts_per_page="4" orderby="date" output_view="lc_get_posts_mycustom_view" output_number_of_columns="4"
output_wrapper_class="row" output_article_class="shadow" output_hide_elements="Excerpt"
output_excerpt_length="0" output_excerpt_text="Read More" output_heading_tag="span"
output_featured_image_format="thumbnail" output_featured_image_class="card-img-left" ]

## Share

[addtoany]

## Subscribe to get latest insights

## Talk to our experts

Get the best ROI with Sigmoid’s services in data engineering and AI

## Suggested readings

[View all](/blogs/)

![Apache Spark for Real-time Analytics](/wp-content/uploads/2022/12/apache-spark-for-real-time-analytics-thumbnail.png)

#### [Apache Spark for Real-time Analytics](/blogs/apache-spark-for-real-time-analytics/)

[Read blog](/blogs/apache-spark-for-real-time-analytics/)

![Why Apache Arrow is the Future for Open Source Columnar](https://www.sigmoid.com/wp-content/uploads/2023/01/Why-Apache-Arrow-is-the-Future-for-Open-Source-Columnar-thumbnail.png)

#### [Why Apache Arrow is the Future for Open Source Columnar](/blogs/apache-arrow-future-open-source-columnar-memory-analytics/)

[Read blog](/blogs/apache-arrow-future-open-source-columnar-memory-analytics/)

![How to Optimize Nested Queries using Apache Spark](https://www.sigmoid.com/wp-content/uploads/2023/01/How-to-Optimize-Nested-Queries-using-Apache-Spark-thumnail.png)

#### [How to Optimize Nested Queries using Apache Spark](/blogs/optimize-nested-queries-using-apache-spark/)

[Read blog](/blogs/optimize-nested-queries-using-apache-spark/)

---

## Categories

- Data Management

---

## Navigation

- [Company](/about-sigmoid)
- [Newsroom](/newsroom)
- [Life at Sigmoid](/careers)
- [Takshashila](/takshashila)
- [Contact Us](/contact-us)
- [AI Strategy Blueprint your AI advantage](/enterprise-ai-strategy/)
- [Generative AI Drive innovation with Generative AI](/generative-ai/)
- [Responsible AI Build trust with ethical AI practices](/responsible-ai-in-enterprise/)
- [Agentic AI Reshape business with scalable agentic systems](/agentic-ai-solutions/)
- [AI Managed Services Ensure reliable AI performance](/ai-managed-services/)
- [Advanced Analytics Transform your business with data-driven insights](/advanced-data-analytics-solutions/)
- [Start Assessment](/agentic-ai-readiness-index/)
- [Data Strategy Strong data foundations for scalable AI](/data-analytics-strategy/)
- [Data Management Leverage data as a strategic asset](/ai-data-management-services/)
- [Data Ops Automate data for speed and quality](/data-devops/)
- [Data Engineering Deliver insights faster with scalable pipelines](/data-engineering/)
- [Cloud Transformation Modernize data to maximise efficiency](/cloud-migration/)
- [Download Whitepaper](/ebooks-whitepapers/building-data-products-in-a-data-mesh-to-drive-business-value/)
- [Data Modeling Structure data for better decisions](/data-modeling-services/)
- [Data Visualization Transform data into actionable stories](/data-visualization-service/)
- [BI Migration Enhance decision making with modern BI tools](/bi-migration/)
- [Data Observability Build trust with healthy, accurate data](/data-observability/)
- [Automated Insights Make smarter decisions with auto-generated insights](/automated-insights/)
- [Download Whitepaper](/ebooks-whitepapers/power-bi-hacks/)
- [CPG & Retail End-to-end analytics for planning, operations, and commercial excellence](/industries/cpg-analytics/)
- [Life Sciences Trusted intelligence across clinical, commercial, and operational workflows](/industries/life-sciences/)
- [Financial Services AI-powered analytics for risk, compliance and customer experience](/industries/banking-financial-analytics-services/)
- [Read case study](/case-studies/data-clean-room-enables-real-time-insights-to-improve-operational-efficiency/)
- [MediaIQ Advanced platform for in-flight marketing measurement](/accelerators/sigmoid-mediaiq-multi-touch-attribution-tool/)
- [CampaignIQ AI-driven platform for optimized campaign budget allocation](/accelerators/sigmoid-campaigniq/)
- [AssistBot GenAI email assistant that automates human-like responses](/accelerators/sigmoid-assistbot-for-ai-email-assistant/)
- [CreativeBot GenAI tool for personalized and brand-aligned creative design](/accelerators/sigmoid-creativebot/)
- [SocialBot GenAI platform to analyze digital conversations and trends](/accelerators/#marketing|socialbot)
- [DemandIQ Predict trends accurately and optimize inventory management](/accelerators/sigmoid-demandiq/)
- [NetworkIQ Track and optimize logistics operations in real-time to quickly address disruptions](/accelerators/sigmoid-networkiq/)
- [SupplyIQ End-to-end platform to optimize supply chain operations](/accelerators/sigmoid-supplyiq/)
- [ProcurementIQ Automated procurement operations for maximum savings, compliance and efficiency](/accelerators/sigmoid-procurementiq/)
- [RapidML Accelerated deployment for machine learning models](/accelerators/sigmoid-rapidml/)
- [DataGuard Comprehensive platform for proactive data quality management](/accelerators/data-quality-tool-sigmoid-dataguard/)
- [CloudPulse Cloud cost optimization platform with multi-cloud management](/accelerators/sigmoid-cloudpulse/)
- [RAPID GenAI foundation with built-in governance and cost clarity](/accelerators/sigmoid-rapid/)
- [AnalyticsBot GenAI based platform to streamline decision-making in analytics](/accelerators/sigmoid-analyticsbot/)
- [DataConnect Seamlessly ingest, integrate and harmonize data from diverse sources](/accelerators/sigmoid-dataconnect/)
- [Reconica AI-powered data harmonization and reconciliation engine](/accelerators/sigmoid-reconica/)
- [ConverseBot GenAI driven insights generation for automated insights from reports](/accelerators/#sales|conversebot)
- [iNRM Cross-lever revenue growth optimization platform](/accelerators/sigmoid-inrm/)
- [AssortmentIQ Optimize shelf layouts and assortment mix at scale with AI-based insights](/accelerators/sigmoid-assortmentiq/)
- [Read Whitepaper](/ebooks-whitepapers/building-agentic-ai-chatbots-for-business-process-transformation/)
- [Listen Podcast](/events/podcast/how-jack-in-the-box-is-redefining-personalization-and-supply-chain-with-ai/)
- [Blogs](/blogs/)
- [White Papers](/ebooks-whitepapers/)
- [Case Studies](/case-studies/)
- [Podcast](/events/podcast/#Podcasts)
- [Read Blog](/blogs/the-genai-adoption-triad-responsibility-ethics-and-explainability/)
- [ConverseBot](/accelerators/#sales|conversebot/)

## Tags

- Cloud Transformation

---

## Footer Links

- [Talk to our AI experts](/contact-us/)
- [AI Strategy](/enterprise-ai-strategy/)
- [Agentic AI](/agentic-ai-solutions/)
- [Generative AI](/generative-ai/)
- [AI Managed Services](/ai-managed-services/)
- [Responsible AI](/responsible-ai-in-enterprise/)
- [Advanced Analytics](/advanced-data-analytics-solutions/)
- [Data Strategy](/data-analytics-strategy//)
- [Data Engineering](/data-engineering/)
- [Data Management](/ai-data-management-services/)
- [Cloud Transformation](/cloud-transformation/)
- [Data Ops](/data-devops/)
- [Data Visualization](/data-visualization-service/)
- [Automated Insights](/automated-insights/)
- [BI Migration](/bi-migration/)
- [Data Modeling](/data-modeling-services/)
- [Data Observability](/data-observability/)
- [CPG & Retail](/industries/cpg-analytics/)
- [Financial Services](/industries/banking-financial-analytics-services/)
- [Life Sciences](/industries/life-sciences/)
- [Case Studies](/case-studies/)
- [Thought Leadership](/ebooks-whitepapers/)
- [Blogs](/blogs/)
- [Company](/about-sigmoid/)
- [Newsroom](/newsroom/)
- [Accelerators](/accelerators/)
- [Careers](/careers/)
- [Privacy Policy |](/privacy-policy/)
- [Cookie Policy](/cookie-policy/)