623

I have heard lots of raving about Akka framework (Java/Scala service platform), but so far have not seen many actual examples of use cases it would be good for. So I would be interested in hearing about things developers have used it succesfully.

Only one limitation: please do not include case of writing a chat server. (why? since this has been overused as an example for lots of similar things)

Christophe
  • 68,716
  • 7
  • 72
  • 138
StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • 10
    Isn't it easier to start with the problem and find a solution for it, than having a solution and looking a problem to apply it on? My guess is that instead using RMI, Akka and its actors look much easier/simpler to write code for. – Kennet Dec 20 '10 at 19:52
  • 75
    Yes, if I had specific problem to solve. I am not looking for an "excuse to use Akka" by any means, but I am interested in learning bit more. This may help solve future problems too, but mostly it's for on-going learning process. – StaxMan Dec 20 '10 at 20:10
  • There is related question but about applying AKKA for existing application + some use cases: http://stackoverflow.com/questions/16595685/example-of-integration-akka-with-existing-java-poject/16674690#16674690 – ses May 21 '13 at 16:31
  • 2
    Akka is a better solution over JMS or an MQ-style distributed messsage queue system. That's the best way to understand it for myself who was recently asking the exact same question: "I understand how to use it and see where I could use it, but I can't see where this would provide a real advantage". The core design assumptions behind Akka are much better than those behind JMS/MQ, specifically regarding process isolation, lock-less design, and retry/failure handling. Secondly, the API is much more elegant than JMS/MQ tools. – user2684301 Jan 14 '14 at 15:25
  • 2
    @user2684301 hmmh. I find that answer bit unfair, in apples-to-oranges way. MQs are (logically) simple building blocks that do much less than Akka, and I would not compare them side by side. But I guess if I read it as "compared to distributed systems built using JMS, written declaratively" then it'd make more sense. – StaxMan Jan 14 '14 at 20:58
  • Absolutely pathetic that such a good question has been closed. – rapt Dec 06 '17 at 23:14
  • Philosophy of AKKA: found this on Akka site: https://doc.akka.io/docs/akka-http/current/introduction.html#philosophy – software.wikipedia Jan 08 '19 at 22:40

12 Answers12

331

I have used it so far in two real projects very successfully. both are in the near real-time traffic information field (traffic as in cars on highways), distributed over several nodes, integrating messages between several parties, reliable backend systems. I'm not at liberty to give specifics on clients yet, when I do get the OK maybe it can be added as a reference.

Akka has really pulled through on those projects, even though we started when it was on version 0.7. (we are using scala by the way)

One of the big advantages is the ease at which you can compose a system out of actors and messages with almost no boilerplating, it scales extremely well without all the complexities of hand-rolled threading and you get asynchronous message passing between objects almost for free.

It is very good in modeling any type of asynchronous message handling. I would prefer to write any type of (web) services system in this style than any other style. (Have you ever tried to write an asynchronous web service (server side) with JAX-WS? that's a lot of plumbing). So I would say any system that does not want to hang on one of its components because everything is implicitly called using synchronous methods, and that one component is locking on something. It is very stable and the let-it-crash + supervisor solution to failure really works well. Everything is easy to setup programmatically and not hard to unit test.

Then there are the excellent add-on modules. The Camel module really plugs in well into Akka and enables such easy development of asynchronous services with configurable endpoints.

I'm very happy with the framework and it is becoming a defacto standard for the connected systems that we build.

Raymond Roestenburg
  • 4,890
  • 2
  • 20
  • 18
  • 15
    What is the benefit of this approach in comparison to using a messaging backend (e.g. ActiveMQ) for message passing in your opinion? – magiconair Sep 23 '12 at 05:26
  • 27
    MQ products are really for a different use case. different guarantees and very different performance. MQ products need a lot of setup, you would not use queues in such a product in the same way as you would use objects. Actors are first class citizens in akka, you use them as you please, similar to how you would use objects, so there is far less of an overhead both in your programming model as in the setup. MQ products you would use more to integrate with other external systems, not to build the 'internals' of a system, which is something you would use actors for. – Raymond Roestenburg Jan 02 '13 at 14:17
  • 27
    New URL for the DBP case study is http://downloads.typesafe.com/website/casestudies/Dutch-Border-Police-Case-Study-v1.3.pdf – Bas Dec 08 '13 at 14:12
  • 2
    Building off @RaymondRoestenburg re: MQ systems and alternatives. RabbitMQ, for example, is built *on* an actor-based programming language, Erlang. That's one way to think about the relation (and distinction) between actor and MQ. Meanwhile [Apache Spark](https://spark.apache.org/) is neither worker-and-queue nor Actor-based, BUT can be used with Akka: [Typesafe demonstrates how to use Spark Streaming with Akka](http://www.typesafe.com/activator/template/spark-streaming-scala-akka). – floer32 May 21 '15 at 20:10
  • 6
    @RaymondRoestenburg You neglected to mention that the Actor model as-is promotes spaghetti-like structure. The "Akka in Action" book you wrote is the best demonstration for this "feature". The code examples deal with fairly basic stories. Yet the workflow is very difficult to comprehend and follow from the code. A related problem is that Akka code will be IRREVERSIBLY all over your business logic in the most intrusive way you could imagine. Much more than any other non-actor framework. It is simply impossible to write a basic workflow without dissecting it into different separate sections. – rapt Dec 06 '17 at 23:52
227

Disclaimer: I am the PO for Akka

Besides offering a concurrency smorgasbord that is much simpler to reason about and to get correct (actors, agents, dataflow concurrency) and with concurrency control in the form of STM.

Here are some use-cases you might consider:

  1. Transaction processing (online gaming, finance, statistics, betting, social media, telecom, ...)
    • scale up, scale out, fault-tolerance / HA
  2. Service backend (any industry, any app)
    • service REST, SOAP, cometd etc
    • act as message hub / integration layer
    • scale up, scale out, fault-tolerance / HA
  3. Snap-in concurrency/parallelism ( any app )
    • Correct
    • Simple to work with and understand
    • Just add the jars to your existing JVM project (use Scala, Java, Groovy or JRuby)
  4. Batch processing ( any industry )
    • Camel integration to hook up with batch data sources
    • Actors divide and conquer the batch workloads
  5. Communications hub ( telecom, web media, mobile media )
    • scale up, scale out, fault-tolerance / HA
  6. Game server (online gaming, betting)
    • scale up, scale out, fault-tolerance / HA
  7. BI/datamining/general purpose crunching
    • scale up, scale out, fault-tolerance / HA
  8. insert other nice use cases here
Viktor Klang
  • 26,479
  • 7
  • 51
  • 68
  • 12
    I understand the benefits of Futures and STM but don't find good use cases for actors. For a game or betting server, what's the advantage of using Actors vs multiple app servers behind a load balancer? – Martin Konicek Jul 10 '13 at 15:41
  • 8
    @ViktorKlang POs != Tech Lead. They work together, but are different roles. – taylorcressy Jul 16 '17 at 00:23
  • I am not able to wrap my head around how Akka can be used for BI/datamining/general purpose crunching – JustTry Jun 11 '23 at 22:46
80

An example of how we use it would be on a priority queue of debit/credit card transactions. We have millions of these and the effort of the work depends on the input string type. If the transaction is of type CHECK we have very little processing but if it is a point of sale then there is lots to do such as merge with meta data (category, label, tags, etc) and provide services (email/sms alerts, fraud detection, low funds balance, etc). Based on the input type we compose classes of various traits (called mixins) necessary to handle the job and then perform the work. All of these jobs come into the same queue in realtime mode from different financial institutions. Once the data is cleansed it is sent to different data stores for persistence, analytics, or pushed to a socket connection, or to Lift comet actor. Working actors are constantly self load balancing the work so that we can process the data as fast as possible. We can also snap in additional services, persistence models, and for critical decision points.

The Erlang OTP style message passing on the JVM makes a great system for developing realtime systems on the shoulders of existing libraries and application servers.

Akka allows you to do message passing like you would in a traditional but with speed! It also gives you tools in the framework to manage the vast amount of actor pools, remote nodes, and fault tolerance that you need for your solution.

surfmuggle
  • 5,527
  • 7
  • 48
  • 77
Wade Arnold
  • 1,026
  • 6
  • 6
  • 1
    So is it fair to say it is case of (some) long-latency requests, where single-thread per request would not scale well? – StaxMan Dec 20 '10 at 22:36
  • 7
    I think the important part of actor programming in general is message flow. Once you start conceptualizing in flows of data that does not have side effects you just want as many flows to happen per node as possible. This is much different than High Performance Computing were you have semi homogenous jobs that do not send messages and take a long time to process. I think an actor based Fibonacci implementation is a very limiting example as it does not showcase why to use actors but only that actors paralyze taks. Think Event-driven architecture for use cases. – Wade Arnold Dec 21 '10 at 02:53
  • Ok. So one important part is that actors are good abstraction for modeling and implementing complex message flows? Sounds like this would be great for many kinds of distributed systems (my experience is mostly with distribute ("nosql") storage, message queues (Sqs)). – StaxMan Dec 21 '10 at 18:26
  • 4
    Event driven architecture is a different way of thinking about problems. It's worth reading Erlang OTP in Action from manning if you are thinking about coding in Akka. A lot of the constructs in akka are influenced by Erlang OTP and the book gives you the principles for why Jonas Boner built akka api the way he did. Akka is a big mountain that you are standing on! If your actors are persistent through state changes do you really need 10k writes a second sustained – Wade Arnold Dec 21 '10 at 20:52
  • 8
    Wade, how do you guys handle message guarantees? you mention: (email/sms alerts, fraud detection, low funds balance, etc), I assume these are potentially sent to remote actors? How do you ensure those operations actually happened? what if the node failed while processing a fraud alert? Is it gone forever? Do you have an eventually consistent system that cleans it up? thanks! – James Jul 16 '12 at 22:43
  • 2
    Good question James. It is obvious that it fits in a system where reply is not needed urgently. For example you can process credit card bills; calculate; send e-mail etc. I really wonder how these things (transaction) are handled when a reply is needed. At the end; if a request is made from external (internet user; a representative from call center etc.); he or she waits a reply. How can I be sure that sub tasks (which are executed async) are executed; in a xa transaction so that I can return reply? – Kaan Yy Sep 05 '12 at 07:55
  • See http://www.lightbend.com/resources/case-studies-and-stories – Jarek Przygódzki Jan 09 '17 at 14:41
  • I think a higher level framework like Kafka is better suited for this, isn't it? – skjagini Sep 18 '19 at 21:32
47

We use Akka to process REST calls asynchronously - together with async web server (Netty-based) we can achieve 10 fold improvement on the number of users served per node/server, comparing to traditional thread per user request model.

Tell it to your boss that your AWS hosting bill is going to drop by the factor of 10 and it is a no-brainer! Shh... dont tell it to Amazon though... :)

piotrga
  • 1,243
  • 12
  • 12
  • 4
    And I forgot to mention that the monadic nature of akka futures, which leads to much cleaner parallel code saved us thousands in code maintenance... – piotrga Nov 17 '12 at 15:13
  • 8
    I assume calls are high-latency, low throughput? Like making calls to other servers, waiting for response (proxy)? – StaxMan Nov 17 '12 at 17:56
39

We are using Akka in a large scale Telco project (unfortunately I can't disclose a lot of details). Akka actors are deployed and accessed remotely by a web application. In this way, we have a simplified RPC model based on Google protobuffer and we achieve parallelism using Akka Futures. So far, this model has worked brilliantly. One note: we are using the Java API.

Luciano Fiandesio
  • 10,037
  • 10
  • 48
  • 56
  • Could you tell us a bit more please? Afaik Futures can't be sent over the wire (serialized). Do you use a lot of futures and few actors or a mix between the two or...? You use protobuf for all serialization and send as a message to the actors? – Aktau Sep 24 '12 at 08:49
  • This seems like it could have been handled just as easily without Akka. – Erik Kaplun Jun 22 '14 at 08:41
  • 1
    TDC is Telco company in Fiaddesio's case. – Roman Kagan Mar 02 '16 at 23:47
38

If you abstract the chat server up a level, then you get the answer.

Akka provides a messaging system that is akin to Erlang's "let it crash" mentality.

So examples are things that need varying levels of durability and reliability of messaging:

  • Chat server
  • Network layer for an MMO
  • Financial data pump
  • Notification system for an iPhone/mobile/whatever app
  • REST Server
  • Maybe something akin to WebMachine (guess)

The nice things about Akka are the choices it affords for persistence, it's STM implementation, REST server and fault-tolerance.

Don't get annoyed by the example of a chat server, think of it as an example of a certain class of solution.

With all their excellent documentation, I feel like a gap is this exact question, use-cases and examples. Keeping in mind the examples are non-trivial.

(Written with only experience of watching videos and playing with the source, I have implemented nothing using akka.)

tylerweir
  • 1,265
  • 11
  • 16
  • 2
    Thanks -- I didn't mean chat server is necessarily bad, just that I would want complementary examples; easier to get better idea of potential. – StaxMan Dec 20 '10 at 22:38
  • Curious to know how the REST server fits here? Are you mentioning it in context of Node.js style async server? Thanks for sharing the example use cases. I found them useful. – software.wikipedia Jan 08 '19 at 22:18
25

You can use Akka for several different kinds of things.

I was working on a website, where I migrated the technology stack to Scala and Akka. We used it for pretty much everything that happened on the website. Even though you might think a Chat example is bad, all are basically the same:

  • Live updates on the website (e.g. views, likes, ...)
  • Showing live user comments
  • Notification services
  • Search and all other kinds of services

Especially the live updates are easy since they boil down to what a Chat example ist. The services part is another interesting topic because you can simply choose to use remote actors and even if your app is not clustered, you can deploy it to different machines with ease.

I am also using Akka for a PCB autorouter application with the idea of being able to scale from a laptop to a data center. The more power you give it, the better the result will be. This is extremely hard to implement if you try to use usual concurrency because Akka gives you also location transparency.

Currently as a free time project, I am building a web framework using only actors. Again the benefits are scalability from a single machine to an entire cluster of machines. Besides, using a message driven approach makes your software service oriented from the start. You have all those nice components, talking to each other but not necessarily knowing each other, living on the same machine, not even in the same data center.

And since Google Reader shut down I started with a RSS reader, using Akka of course. It is all about encapsulated services for me. As a conclusion: The actor model itself is what you should adopt first and Akka is a very reliable framework helping you to implement it with a lot of benefits you will receive along the way.

Joa Ebert
  • 6,565
  • 7
  • 33
  • 47
  • Hello Joe, could you explain how messages are used to update the site? Do you have one system for the content author; he creates a new article and hits save. Does this create a message that is send to several servers that handle the incoming traffic. Each server processes the update-message as soon as they can. Every fresh browser-request then gets an updated version of the page? Thank you – surfmuggle Sep 26 '18 at 21:28
25

We use Akka in several projects at work, the most interesting of which is related to vehicle crash repair. Primarily in the UK but now expanding to the US, Asia, Australasia and Europe. We use actors to ensure that crash repair information is provided realtime to enable the safe and cost effective repair of vehicles.

The question with Akka is really more 'what can't you do with Akka'. Its ability to integrate with powerful frameworks, its powerful abstraction and all of the fault tolerance aspects make it a very comprehensive toolkit.

rossputin
  • 251
  • 2
  • 2
  • So which aspect do you like most if you had to choose? Existing integration for other frameworks, automatic fault tolerance, or something else? – StaxMan Dec 21 '10 at 18:23
  • 6
    From a personal perspective it is the raised abstraction level which Akka brings to the table that I like best. From an enterprise perspective it is the integration capabilities. Got to make a living and Akka covers business and pleasure both very nicely :-) – rossputin Dec 23 '10 at 15:51
  • Could you elaborate how the flow of messages is? Is the user the person in a repair shop and enters details about the crash into a http-form and then sends the data to the server. Does this create a message that is handled by akka? To do what with this message? Extract the entered information to query the database and then queue the reply to send it back to the web-frontend? – surfmuggle Sep 26 '18 at 21:24
20

I was trying out my hands on Akka (Java api). What I tried was to compare Akka's actor based concurrency model with that of plain Java concurrency model (java.util.concurrent classes).

The use case was a simple canonical map reduce implementation of character count. The dataset was a collection of randomly generated strings (400 chars in length), and calculate the number of vowels in them.

For Akka I used a BalancedDispatcher(for load balancing amongst threads) and RoundRobinRouter (to keep a limit on my function actors). For Java, I used simple fork join technique (implemented without any work stealing algorithm) that would fork map/reduce executions and join the results. Intermediate results were held in blocking queues to make even the joining as parallel as possible. Probably, if I am not wrong, that would mimic somehow the "mailbox" concept of Akka actors, where they receive messages.

Observation: Till medium loads (~50000 string input) the results were comparable, varying slightly in different iterations. However, as I increased my load to ~100000 it would hang the Java solution. I configured the Java solution with 20-30 threads under this condition and it failed in all iterations.

Increasing the load to 1000000, was fatal for Akka as well. I can share the code with anyone interested to have a cross check.

So for me, it seems Akka scales out better than traditional Java multithreaded solution. And probably the reason is the under the hood magic of Scala.

If I can model a problem domain as an event driven message passing one, I think Akka is a good choice for the JVM.

Test performed on: Java version:1.6 IDE: Eclipse 3.7 Windows Vista 32 bit. 3GB ram. Intel Core i5 processor, 2.5 GHz clock speed

Please note, the problem domain used for the test can be debated and I tried to be as much fair as my Java knowledge allowed :-)

sutanu dalui
  • 663
  • 7
  • 25
  • 3
    "I can share the code with anyone interested to have a cross check." I would like to if you don't mind. – n1r3 Sep 05 '12 at 09:38
  • 3
    I would also like the code, can you post a github link ? – Gautam Oct 31 '12 at 05:58
  • Thank you for your interest. Unfortunately I have some problems setting up a github repo. If you can give me your emails, I can mail over the source code. And regrets for a late reply! – sutanu dalui Jan 31 '13 at 06:38
  • @sutanudalui Do you still have the code please, if so I can share my email ? – Jay Jun 17 '15 at 10:29
18

We are using akka with its camel plugin to distribute our analysis and trending processing for twimpact.com. We have to process between 50 and 1000 messages per second. In addition to multi-node processing with camel it is also used to distribute work on a single processor to multiple workers for maximum performance. Works quite well, but requires some understanding of how to handle congestions.

17

We use Akka in spoken dialog systems (primetalk). Both internally and externally. In order to simultaneously run a lot of telephony channels on a single cluster node it is obviously necessary to have some multithreading framework. Akka works just perfect. We have previous nightmare with the java-concurrency. And with Akka it is just like a swing — it simply works. Robust and reliable. 24*7, non-stop.

Inside a channel we have real-time stream of events that are processed in parallel. In particular: - lengthy automatic speech recognition — is done with an actor; - audio output producer that mixes a few audio sources (including synthesized speech); - text-to-speech conversion is a separate set of actors shared between channels; - semantic and knowledge processing.

To make interconnections of complex signal processing we use SynapseGrid. It has the benefit of compile-time checking of the DataFlow in the complex actor systems.

Arseniy Zhizhelev
  • 2,381
  • 17
  • 21
15

I've recently implemented the canonical map-reduce example in Akka: Word count. So it's one use case of Akka: better performance. It was more of a experiment of JRuby and Akka's actors than anything else, but it also shows that Akka is not Scala or Java only: it works on all languages on top of JVM.

Daniel Ribeiro
  • 3,110
  • 3
  • 23
  • 49
  • Do you know what is responsible for better performance (and also compared to which alternative)? Is that due to using JRuby on JVM (vs native Ruby), scalalibiliy due to non-blocking I/O or something else? – StaxMan Dec 21 '10 at 18:24
  • 2
    The comparison I wrote was: Jruby sequential VS Jruby with actors. Therefore, the only thing that can be responsible for faster execution is the participation of the actors. No I/O participated on the experiments (a file is load from disk, but it is done before the benchmark timer is set). – Daniel Ribeiro Dec 22 '10 at 01:10
  • I've recently implemented a map reduce example as well, but it's just plain vanilla java https://github.com/chaostheory/jibenakka – chaostheory Aug 27 '11 at 07:35