-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Welcome to the reactive-toolbox wiki!
Reactive Toolbox is a highly opinionated framework for writing modern, fast and efficient backend applications.
Every project is started because of some kind of motivation behind it.Reactive Toolbox is not an exception.
The Reactive Toolbox was started as a research for new ways to write Java (and not just Java) backend applications. The main reason is heavy dissatisfaction of current state of the things:
- Heavily outdated and error prone approaches.
Most Java backend application still written using synchronous code, using frameworks which use unnecessarily high amount of runtime reflection and promote "best practices" like code in string constants and exceptions in business logic. - Unacceptably high mental overhead doing projects using traditional approaches.
Traditional approaches are inherently unsafe and this means that a lot of mental resources are spent to keep in mind potential pitfalls.
Since modern applications are quickly increasing complexity all of the above means that traditional approaches are no more acceptable. Moreover, they are not fun anymore!
Reactive Toolbox borrows several ideas from Functional Programming to reduce mental overhead. Beside core things like immutability and heavy use of Monads and Monadic behavior, Reactive Toolbox attempts to make incorrect states unrepresentable. Together these approaches significantly simplify writing code. The code overall is much more declarative, simple to write and read, even when you read code written quite long ago. Other things which reduce mental overhead:
- Avoid using exceptions as much as possible and use Result to represent result of operation.
- Clear separation of nullable and non-nullable values (parameters and results) by using Option to represent nullable values.
Reactive Toolbox adopts asynchronous processing model based on Promises. This is the same approach as one used in JavaScript, although actual implementation and API is significantly different. The Promise-based model has several advantages:
- It's quite convenient for writing even complex processing scenarios without creating callback hell.
- It allows writing easily scalable parallel processing code without worrying about synchronization and concurrent access issues.
- Unlike some other asynchronous processing models it does not introduce any artificial entities like Observable Streams.
The Promise-based model is very close to how application actually looks like from the point of view of I/O. This means that by writing application this way we reducing abstraction overhead to minimum.
Reactive Toolbox has built-in scheduler tuned for processing huge amounts of very small tasks. The Scheduler uses all CPU power available to application as efficiently as possible. The Scheduler achieves this with minimal possible number of threads, minimal number of context switches and minimal thread contention even on CPU's with high number of cores. Overall Task Scheduler is a perfect match for Promise-based asynchronous processing model. Unless application does something very unusual, there is no need to have any other threads or thread pools.
Reactive Toolbox is build around asynchronous I/O API introduced in Linix 5.1+ - io_uring. This API provides very natural and extremely efficient API for implementation of Proactor pattern which is a perfect fit for the Promise-based Asynchronous Processing Model. One of less visible but extremely important properties of the io_uring API: it enables batching/unbatching of the requests/responses when they cross application<->OS kernel boundary. This results to high efficiency while keeping Reactive Toolbox API's simple and transparent.