You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2024. It is now read-only.
After a long hiatus, I am back with renewed passion and energy, eager to delve deeper into the Scala ecosystem. This time, I am committed to building something tangible and useful with the tools available. Let's embark on this exciting journey of exploration and learning together.
12
+
{% include video id="1uP6FTUn8_E" provider="youtube" %}
15
13
16
-
The greatest benefit of small side projects is the unique knowledge boost which can potentially be handy later in career.
14
+
## 1. Introduction
17
15
18
-
In this article we will attempt to build the remote code execution engine - the backend platform for websites such as [Hackerrank](https://hackerrank.com), [Leetcode](https://leetcode.com) and others.
16
+
In this article we will attempt to build the remote code execution engine - the backend platform for websites such as [Hackerrank](https://hackerrank.com), [LeetCode](https://leetcode.com) and others.
19
17
20
-
If, for some reason you're unfamiliar with the websites mentioned above, the basic usage flow is described below:
18
+
For such a platform, the basic usage flow is:
21
19
- Client sends code
22
20
- Backend runs it and responds with output
23
21
24
-
There you go, sounds simple, right?
22
+
Sounds simple, right? Right?...
25
23
26
-
Right, right...
24
+
Can you imagine how many things can go wrong here? The possibilities for failure are endless! However, we should address at least some of them.
27
25
28
-
Can you imagine how many things can go wrong here? It's the devil smirking in the corner, knowing, that the possibilities for failure are endless, however, we should address at least some of them.
29
-
30
-
To give you a quick idea: a separate blog post can be written only about the security, not to mention scalability, extensibility and a few other compulsory properties to make it production ready.
26
+
We can probably write a separate blog post about the security, scalability, extensibility and a few other compulsory properties to make it production ready.
31
27
32
28
The goal isn't to build the best one, nor it is to compete with the existing ones.
33
29
34
-
Put simply, the goal of this project is to get familiar with `Pekko`and its modules such as `pekko-http`, `pekko-stream`, `pekko-cluster` and a few interesting concepts revolving around actor model concurrency, such as:
30
+
Put simply, the goal of this project is to get familiar with [Apache Pekko](https://pekko.apache.org) (the open source version of Akka) and its modules such as `pekko-http`, `pekko-stream`, `pekko-cluster` and a few interesting concepts around actor model concurrency, such as:
35
31
- cluster nodes and formation
36
32
- cluster aware routers
37
33
- remote worker actors
@@ -43,9 +39,11 @@ Put simply, the goal of this project is to get familiar with `Pekko` and its mod
43
39
44
40
Let's get started then, shall we?
45
41
42
+
> _Hey, it's Daniel here. Apache Pekko is great, and Nika has done a great job showcasing its features in a compact project we can explore exhaustively in this article. If you need to get started with Pekko, I've covered Pekko (and Akka) in a comprehensive bundle of courses about [Akka/Pekko Actors](https://rockthejvm.com/p/akka-essentials), [Akka/Pekko Streams](https://rockthejvm.com/p/akka-streams), and [Akka/Pekko HTTP](https://rockthejvm.com/p/akka-http), all of which are used in this article. Check them out if you're interested._
43
+
46
44
## 2. Project Structure - here
47
45
48
-
I recommend checking out [the project on GitHub](https://github.com/ghurtchu/braindrill/) and following along that way.
46
+
To make the best of this article, I recommend checking out [the project on GitHub](https://github.com/ghurtchu/braindrill/) and following the code while reading this article, as many things will make sense along the way.
49
47
50
48
We will use `Scala 3.4.1`, `sbt 1.9.9`, `docker`, `pekko` and its modules to complete our project.
51
49
@@ -64,7 +62,8 @@ The initial project skeleton looks like the following:
64
62
-`Dockerfile` blueprint for running the app inside container
65
63
-`README.md` instructions for setting up the project locally
66
64
67
-
Nothing fancy, let's move on `build.sbt`:
65
+
Let's start with `build.sbt`:
66
+
68
67
```scala
69
68
ThisBuild/ scalaVersion :="3.4.1"
70
69
@@ -120,14 +119,13 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1") // SBT plugin for using
120
119
121
120
## 3. Project Architecture
122
121
123
-
After a few iterations I came up with the architecture that can be horizontally scaled, if required.
124
-
Ideally, such projects must be scaled easily as long as the load is increased.
122
+
After a few iterations I came up with the architecture that can be horizontally scaled, if required. Ideally, such projects should be scaled easily as long as the load is increased.
125
123
126
-
For that we use tools such as Kubernetes or other container orchestration platforms. To make local development and deployment simpler we'll be using docker containers. More precisely we'll be using `docker-compose` to run a few containers together so that they form the cluster.
124
+
For that we use tools such as Kubernetes or other container orchestration platforms. To make local development and deployment simpler we'll be using Docker containers. More precisely we'll be using `docker-compose` to run a few containers together so that they form the cluster.
127
125
128
-
`docker-compose` doesn't support scalability out of the box because it's static, it means that we can't magically add new `worker`node to the running system. Again, for that we'd use Kubernetes, but it is out of the scope of this project.
126
+
`docker-compose` doesn't support scalability out of the box because it's static, it means that we can't magically add new `worker`nodes to the running system. Again, for that we'd use Kubernetes, but it is out of the scope of this project.
129
127
130
-
We have a `master` node and its role is to be the task distributor among `worker` nodes.
128
+
We have a `master` node and its role is to be the task distributor among `worker` nodes.
131
129
132
130
`http` is exposed on `master` node, acting as a gateway to outside world.
133
131
@@ -517,8 +515,8 @@ transformation {
517
515
load-balancer = 3
518
516
}
519
517
```
520
-
Here, it simply means that each node will have 32 worker actors and master node will have 3 load balancer actors.
521
-
In real world, choosing those numbers would depend on multiple variables that must be collected and analyzed in production.
518
+
Here, it means that each node will have 32 worker actors and master node will have 3 load balancer actors.
519
+
In the real world, choosing those numbers would depend on multiple variables that must be collected and analyzed in production.
522
520
In my opinion, those numbers are optimized based on empirical evidence rather than theoretical results.
@@ -1465,8 +1466,3 @@ The design choices made in this project ensure that our remote code execution en
1465
1466
Building this distributed system with Scala 3 and Apache Pekko has been an enlightening experience. We've harnessed the power of actor-based concurrency, cluster management, and containerization to create a resilient and secure remote code execution engine. This project exemplifies how modern technologies can be integrated to solve complex problems in a scalable and efficient manner.
1466
1467
1467
1468
Whether you're looking to implement a similar system or seeking insights into distributed computing with Scala and Pekko, we hope this blog post has provided valuable knowledge and inspiration.
1468
-
1469
-
Additionally, you can check out:
1470
-
-[Video demo](https://www.youtube.com/watch?v=sMlJC7Kr330) which includes running the `Simulator.scala`
0 commit comments