So you want to introduce ZIO to your existing Scala codebase. Great Idea!
It will make your code more efficient, readable, composable and safe.
For the past year we have done this at my team at Wix and we have learned a lot about how to do it right.
In this talk you will see how to successfully use ZIO in your legacy service using real-life code examples.
You will learn key tips and takeaways including:
- How and when to execute the ZIO runtime
- How/When to introduce ZLayers into your codebase
- How to make your existing APIs interop with ZIO
- How to have more flexibility on ZManaged resource shutdown
4. @NSilnitsky
1.5B
Kafka Messages per day
Data Streams
At Wix
900
Developers
1500
Microservices use our Kafka infra called Greyhound
Developing Event driven Infrastructure
6. @NSilnitsky
Greyhound
Service A Service B
Kafka
Consumer
Kafka
Producer
Kafka Broker
Abstracts
so that it is easy to
change for everyone
Simplify
APIs
with additional features
Data Streams
At Wix
9. @NSilnitsky
SDK Libraries
+ as a gRPC proxy
Infra Services
replication, monitoring
Kafka Control plane Services
“Backoffice”
Greyhound
Kafka
Consumer
Kafka
Producer
Kafka Broker
Before Zio
Written in
Scala
12. @NSilnitsky
ZIO benefits
1. Lightweight fibers instead of threads
2. Constrain level of parallelism - ZIO.collectAllParN
3. No implicit ExecutionContext
4. Easy retries: effect.retry(Schedule.spaced(1.seconds) && Schedule.recurs(3))
5. Better error handling - complete and flexible
6. Lazy evaluation and Referential transparency - easy refactoring and local reasoning
Before Zio
13. @NSilnitsky
Greyhound
SDK Libraries
+ as a gRPC sidecar
Infra Services
replication, monitoring, DynamoDB proxy
Kafka Control Plane Services
“Backoffice”
Written in
Scala
Before Zio
How to
migrate to
ZIO???
15. @NSilnitsky
The goal is NOT
getting all the code
wrapped in functional
effects.
Migrating to Zio
Runtime.unsafeRun {
for {
<All app code converted
to functional effects>
} yield ()
}
21. @NSilnitsky
Migrating to Zio
Your App
Non ZIO
FWs
Play,
Akka,
Kafka
Non ZIO
FWs
Play,
Akka,
Kafka
HTTP
DB
Kafka
HTTP
RPC
Kafka
Endpoints
Step 2
How to Create ZIO Wrapper APIs or switch library
✔
22. Migrating to Zio
How to Create ZIO Wrapper APIs or switch library
Demo
Your App
Non ZIO
FWs
Play,
Akka,
Kafka
HTTP
DB
Kafka
24. Migrating to Zio
How to Switch to a ZIO-based FW Demo
Your App
Non ZIO
FWs
Play,
Akka,
Kafka
HTTP
DB
Kafka
HTTP
RPC
Kafka
Endpoints
25. Wrap segments with Runtime
Step 1
Step 2
Create ZIO Wrapper APIs or switch library
Extract runtime call or Switch to a ZIO-based solution
Step 3
Migrating to Zio
26. ENJOY WRITING IN ZIO
WRITE ALL NEW CODE IN ZIO, EVEN WHEN JUST
INTRODUCING A NEW CLASS IN A LEGACY PROJECT
MIGRATE OLD CODE GRADUALLY.
SWITCH LEGACY LIBRARIES TO ZIO-BASED LIBRARIES.