Integration / Akka interview questions
1. What is Akka?
Akka is a toolkit (not a framework) for building highly concurrent, distributed, and resilient message-driven applications for Java and Scala. Akka is the implementation of the Actor Model on the JVM.
2. What is Actor?
Actors are message driven, stateful building blocks. Messages are passed asynchronously. Actors may create other actors and form supervision hierarchies. Actors are lightweight and won't hold threads.
3. What are reactive streams?
Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non- blocking backpressure.
4. Difference between Java 9 Reactive streams versus Akka Streams.
Akka streams are created on top of Reactive streams so the terminology is different however the workflow/functionality resembles.
5. Can Akka be used instead of the Spring framework?
Akka is a toolkit, not a framework. This means that you use it together with Spring, Akka for structuring your runtime aspects (concurrency, parallelism, fault-handling) while the other for wiring together components.
6. What are the problems that the common programming practices face?
One of the OOPS principles, encapsulation, cannot be addressed efficiently without using locks which is expensive. Sharing memory/data using volatile markers or Atomic wrappers is a costly operation. Concurrency with work delegation needs to handle service faults.
7. How the Actor Model addresses common programming practice issues?
Common programming practices do not properly address the needs of demanding modern, distributed systems. Use of actors model allows us to:, Enforce encapsulation without resorting to locks. Use the model of cooperative entities reacting to signals, changing state, and sending signals to each othe...
8. Components of an Actor.
Each Actor will have these component to achive the messaging behavior. mailbox , (the queue where messages end up) behavior (the state of the actor, internal variables, etc.). Messages (pieces of data representing a signal, similar to method calls and their parameters). Execution environment (the...
9. How Actors handle error situations gracefully?
When the delegated task on the target actor failed due to an error in the task, service actor will reply to the sender with a message about the error case. Akka enforces that all actors are organized into a tree-like hierarchy, i.e. an actor that creates another actor becomes the parent of that n...
10. Mention some of the Akka libraries that you are aware of/worked with.
Actor library , core Akka library that provides a consistent, integrated model that relieves you from individually solving the challenges that arise in concurrent or distributed system design. Remoting enables actors that live on different computers to seamlessly exchange messages. Cluster mainta...
11. Benefits of using the Actor model.
Event-driven model : Actors perform work in response to messages. Communication between Actors is asynchronous, allowing Actors to send messages and continue their own work without blocking to wait for a reply. Strong isolation principles : There is no sharing of state between Actors; the only wa...
12. Should the actor messages be immutable?
Yes. Messages must be immutable as it is shared across different threads.
13. How do you instantiate an Actor?
You cannot create an instance of an Actor using the new keyword. Instead, you create Actor instances using a factory ( akka.actor.ActorSystem ) which does not return an actor instance, but a reference, akka.actor.ActorRef , that points to the actor instance. The akka.actor.ActorSystem factory act...
14. Explain the Akka actor hierarchy.
An actor in Akka always belongs to a parent. getContext().actorOf() creates an actor and inject it as a child into an existing tree. Thus the creator actor becomes the parent of the newly created child actor. All actors have a common parent, the user guardian . Before you create an actor in your ...
15. context.actorOf vs system.actorOf in Akka tool kit.
Both create actors however the difference lies where the actors are created in the actor tree hierarchy. Actors spawned with System.actorOf will be children of the guardian actor while the actors spawned with context.actorOf will be children of the context itself - i.e. the actor which invokes th...
16. Akka actor life cycle hooks.
preStart () is invoked after the actor has started but before it processes its first message. postStop () is invoked just before the actor stops. No messages are processed after this point. package net.javapedia.akka.example; import akka.actor.AbstractActor; import akka.actor.ActorRef; import akk...
17. Different message delivery semantics.
At-most-once delivery : each message is delivered zero or one time, implies that messages can be lost, but are never duplicated. This is the default behavior which is cheap and produces high performance. At-least-once delivery : multiple attempts may be made to deliver each message, until at leas...
18. Advantages of using Akka model.
Simple and high-level abstractions for distribution, concurrency and parallelism. Asynchronous, non-blocking and highly performant message-driven programming model. Very lightweight event-driven processes (several million actors per GB of heap memory).
19. Is Actor system heavy weight?
Yes. ActorSystem is a heavyweight while Actor is light weight. So keep 1 ActorSystem per logical application.
20. Different supervision strategies.
OneForOneStrategy (default). AllForOneStrategy. Both are configured with a mapping from exception type to supervision directive. The difference is OneForOneStrategy applies directive only to the failed child while AllForOneStraegy applies to all siblings. The AllForOneStrategy is applicable in cas...
21. What are the children of the root guardian?
/ user is the guardian actor for all user-created top-level actors; actors created using ActorSystem.actorOf are found below this one. / system is the guardian actor for all system-created top-level actors, e.g. logging listeners or actors automatically deployed by configuration at the start of th...
22. Can Actor beans be singleton when using Dependency injection (DI)?
No . Actor beans must not have singleton scope when using DI frameworks such as Spring, Guice etc.
23. Difference between tell and ask method in AKKA.
Both methods can be used to send messages to the actor. "tell" method send a message asynchronously and return immediately. The "tell" method works like "fire and forget". "ask" method is similar to tell method, send messages asynchronously and return Future object which expect a possible reply. ...