Image for post
Image for post
image source — quora.com

Why is RDD immutable?

Amit Singh Rathore
Apr 25, 2020 · 2 min read

What benefit do we get out of it?

Before I go further, what is RDD? — RDD is not a collection of Data. RDD is an abstraction to create a collection of data. It is just a set of description or metadata which will, in turn, when acted upon, give you a collection of data.

Now the why? First thing, Spark is written in Scala, which supports various aspects of functional programming like currying, lazy evaluation, and so on. In my opinion Spark developer might have decided to leverage this aspect and they might have decided that they need an abstraction that will be computed in a deterministic way and should be able to support concurrent consumption. RDD's immutability fits right in the slot here. Spark speeds up performance by using in-memory computations. It's very likely that you will want your in-memory “stuff” to be immutable since it will remove the need for the frequent cache invalidation. Again RDDs immutability fits in here. Multiple threads accessing the same data and operating on that, immutability removes any requirements of sync up between nodes in a distributed environment.

Lineage: Just think if RDDs are not immutable. Will we be able to deterministically regenerate the previous step once we encounter failure? — No.

I guess we have enough arguments why RDDs are immutable.

Happy Learning!

Nerd For Tech

From Confusion to Clarification

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store