We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies.

We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies. Less

We use cookies and other tracking technologies... More

Login or register
to apply for this job!

Login or register
to save this job!

Login or register to start contributing with an article!

Login or register
to see more jobs from this company!

Login or register
to boost this post!

Show some love to the author of this blog by giving their post some rocket fuel 🚀.

Login or register to search for your ideal job!

Login or register to start working on this issue!

Engineers who find a new job through Functional Works average a 15% increase in salary 🚀

Blog hero image

Akka Actors - Part 1: Why Akka in the first place?

Ravi Allishe 24 August, 2020 | 2 min read

Background: In the early years, softwares were run on a single processor. Looking at the history, the market has always demanded the increase in data and it's computation along with faster performance.

To achieve it, a multi-core processor were developed, and so was the software written in multi-threaded code to make use of a multi-core processor ensuring faster performance.

Problem: Multithreaded programs allow for concurrency(executing multiple parts of programs at the same time) and share the same state but there are following issues.

The common problem experienced is a race condition that occurs when the process is critically dependent on the sequence of events. refer below snippet.

int x

if (x > 0) { return true } else { return false

  } 
This looks simple but suppose if second thread changes x to a negative right after the first thread passed the if-test, we’d still get true even if x is no longer positive.

Solution 1 and problems associated with it:

  • These problems occur because of the OOP's encapsulation break where state and behavior is exposed as anyone can access the state and change its behavior at any time but it's different with Actors that we will see further.
  • Synchronization by using locks comes to rescue the breaking of encapsulation to achieve thread-safety but the problem is it's a blocking call.
  • The blocking call leads to the deadlock. Deadlock occurs with synchronous locking(blocking process) for access to one or more shared resources like variables and objects.

Thread 1 { acquired Resource 1 waiting for Resourse 2 } Thread 2 { acquired Resource 2 waiting for Resourse 1 } No alt text provided for this image

  • To avoid deadlock, we then might want to use asynchronous locking but again there will be other problems arising like Livelock(keeping it short here the point is programmer has to put more time on handling and maintaining the code rather than focusing on business logic).
  • At some point, it gets more and more difficult to maintain and understand when the lines of code increases.
  • So, Multithreaded processes are quite complicated. Coding for these can only be handled by expert programmers.

Is there an easy way out where you get to focus on solving "what" part of actual business logic and not on "how" to achieve it? Solution 2:

Yes, Akka Actors it is.

  • The state is not shared here in Akka and that is achieved by not breaking the encapsulation.
  • The message passing technique is used to communicate between threads, so as to preserve the encapsulation.
  • How this is achieved and it's benefits, I'll talk in "Akka Actors - Part 2"

Originally published on www.linkedin.com

Author's avatar
Ravi Allishe
Skills: Agile Practices: TDD, Pair Programming, CI/CD, Clean Code, Refactoring Programming Languages: Scala, Java, JavaScript Databases: MongoDB, Stardog, Marklogic, PostgreSQL Framework: Play Framework Technologies: Akka actors, Akka streams Tools: Docker, Git Learning: Docker with Kubernetes
    Scala
    akka actors
    akka streams
    docker
    NoSQL

Related Issues

WorksHub / client
  • Started
  • 0
  • 16
  • Intermediate
  • Clojure
  • $150
viebel / klipse-clj
viebel / klipse-clj
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • 1
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Started
  • 0
  • 2
  • Intermediate
  • Clojure
  • $80
viebel / klipse
  • Open
  • 0
  • 0
  • Advanced
  • Clojure
  • $80
viebel / klipse
  • Started
  • 0
  • 2
  • Advanced
  • Clojure
  • $180
viebel / klipse
  • Started
  • 0
  • 1
  • Intermediate
  • Clojure
viebel / klipse
  • 1
  • 1
  • Advanced
  • Clojure
  • $300

Get hired!

Sign up now and apply for roles at companies that interest you.

Engineers who find a new job through Functional Works average a 15% increase in salary.

Start with GitHubStart with Stack OverflowStart with Email