DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Scala vs. Python for Apache Spark

Scala vs. Python for Apache Spark

When using Apache Spark for cluster computing, you'll need to choose your language. Scala has its advantages, but see why Python is catching up fast.

Tim Spann user avatar by
Tim Spann
CORE ·
Feb. 13, 18 · Analysis
Like (13)
Save
Tweet
Share
31.04K Views

Join the DZone community and get the full member experience.

Join For Free

Apache Spark is a great choice for cluster computing and includes language APIs for Scala, Java, Python, and R. Apache Spark includes libraries for SQL, streaming, machine learning, and graph processing. This broad set of functionality leads many developers to start developing against Apache Spark for distributed applications.   

The first big decision you have is where to run it. For most, that's a no-brainer - run it on Apache Hadoop YARN on your existing cluster. After that tough decision, the harder one for developers and enterprises is what language to develop in. Do you have to allow users to pick their own and support multiple languages? This will result in code and tool sprawl, and the R interface is not quite as rich. For most enterprises, seeing how verbose and uncommon the Java interface is, this leads them down the path to either Python or Scala. I am here to tear apart both options and rebuild them and see who is left standing.

Scala has a major advantage in that it is the language that the Apache Spark platform is written in. Scala on JVM is a very powerful language that is cleaner than Java and just as powerful. Using the JVM, your applications can scale to a massive size. For most applications, this is a big deal, but with Apache Spark already being distributed with Akka and YARN, it's not necessary. You merely set a few parameters and your Apache Spark application will be distributed for you regardless of your language. So, this is not an advantage anymore.

Python has become a first-class citizen in the Spark World. It is also a very easy language to start with and many schools are teaching it to children. There is a wealth of example code, books, articles, libraries, documentation, and help available for this language.

PySpark is the default place to be in Spark. With Apache Zeppelin's strong PySpark support, as well as Jupyter and IBM DSX using Python as a first-class language, you have many notebooks to use to develop code, test it, run queries, build visualizations and collaborate with others.   Python is becoming the lingua franca for Data Scientists, Data Engineers, and Streaming developers. Python also is well integrated with Apache NiFi.

Python has the advantage of a very rich set of machine learning, processing, NLP, and deep learning libraries available. You also don't need to compile your code first and worry about complex JVM packaging. Using Anaconda or Pip is pretty standard and Apache Hadoop and Apache Spark clusters already have Python and their libraries installed for other purposes like Apache Ambari.

Some of the amazing libraries available for Python include NLTK, TensorFlow, Apache MXNet, TextBlob, SpaCY, and Numpy.

Python Pros

  • PySpark is listed in all the examples and is no longer an afterthought.   

  • Most libraries come out with Python APIs first.

  • Python is a mature language.

  • Python usage continues to grow.

  • Deep learning libraries are including Python.

  • Included in all notebooks.

  • Ease of use.

Python Cons

  • Sometimes Python 2 and Sometimes Python 3

  • Not as fast as Scala (though Cython fixes it)

  • Some of the libraries are tricky to build


Scala Pros

  • JVM

  • Strong IDEs and unit testing

  • Great serialization formats

  • Reuse Java libraries

  • Fast

  • AKKA

  • Spark Shell

  • Advanced Streaming Capabilities

Scala Cons

  • Not as wide spread use or knowledge base

  • It's a little odd for Java people to move to

  • Has to compiled for Apache Spark jobs


References:

  • http://spark.apache.org/docs/latest/quick-start.html

  • http://spark.apache.org/docs/latest/

  • https://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.6.4/bk_zeppelin-component-guide/content/ch_overview.html

Great Comment from Lightbend's Gerard Maas:

Gerard Maas  

This article misses an important point: With the introduction of high-level abstractions in Spark SQL such as DataFrames/Datasets, the support for Scala and Python are at the same level, both in terms of API (DSL) and performance. These APIs are the currently recommended entry points to program in Spark. In the streaming department, advanced state management is currently supported only in Scala. 


Apache Spark Python (language) Scala (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Was the Question Again, ChatGPT?
  • The Importance of Delegation in Management Teams
  • Taming Cloud Costs With Infracost
  • Remote Debugging Dangers and Pitfalls

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: