Why Developers Should Pay Attention to ZIO in 2022
A growing number of companies try to adopt functional programming or some elements of this programming paradigm, so they can take what’s best from both worlds (functional & object-oriented programming). Actual feelings about 14 functional languages on the web, you can see on the Functional Programming Languages Sentiment Ranking page. But, this mindset of people is slowly changing even more now, with the introduction of ZIO. We already know the cases of big companies like Apple, DHL, and Wix.com, and small adopting ZIO in their production apps. Recently, we’ve asked ZIO experts why they choose ZIO. Among the answers, we found out a lot of practical information. To understand the mindset about ZIO, It’s time to focus on this purely functional library and the question of why you should pay attention to it. Let’s dive into some details.
- What is ZIO?
- Is ZIO production ready?
- What’s in ZIO for programmers and the business?
- What companies are using ZIO, and how?
- How can I contribute?
What is ZIO?
ZIO is a purely functional, type-safe, and composable library for asynchronous, concurrent programming in Scala. ZIO is ideal for mid to large-scale projects that require a lot of concurrency and speed.
It was developed to solve complex, modern business problems using simple, testable, and composable code. Powered by highly-scalable, non-blocking fibers that never waste or leak resources, ZIO supports you in developing highly scalable, resilient, and reactive applications.
Is ZIO production ready?
After 3 years, 459 contributors working long hours and many deployments, ZIO 1.0 was released on August 4, 2020. It seems fresh, but we can’t even tell you how game-changing it can be for a project. But is it production-ready?
Instead of telling you straight away about all the benefits and novelties and listing all the companies using ZIO, first, we want you to see for yourself how the CEO of Fugo.ai and our client, Zuka Kakabadze – answers questions about using ZIO in production.
Fugo is easy digital signage software. It allows users to publish content on their screens and monitor the screens and measure the content’s effectiveness based on face recognition. It was a great challenge to build it together with Fugo from scratch, mainly because it allowed us to use future technologies like ZIO.
In the above video, Zuka Kakabadze mentions that ZIO…
Gives the ability to break down the problem to smaller problems, and then solve them individually. The beauty comes when you start composing those solutions into a new solution. The composition and abstraction gives you the ability to reuse code across your codebase and team members. That’s when you get efficiency and speed. It results in building higher quality software. It’s not only you are building quicker; you build high-quality software as well.
So that’s what the client experience says about ZIO. Now let’s move on to developers and companies they represent.
How are companies all around the world using ZIO?
The programmers’ community buzz is on. Hello ZIO!
At the Scale BY The Bay 2020 Conference, we had the opportunity to not only be sponsors and speakers but observe the rise of ZIO with our own ears and eyes. There were quite a few presentations about ZIO from top brands like Apple or Collective Health.
Developers use ZIO with microservices and machine learning projects, and that’s just the top of the mountain. Let’s see some examples.
Increasing type safety and allowing coordination of state changes across multiple actors
Actors are a cornerstone of modern concurrent and distributed systems, propelling Erlang and Scala to early success. Exposing a model that doesn’t require locks and which doesn’t block threads, actors have helped developers build software without worrying about deadlocks, thread management, and other modern software development woes. In this presentation, Salar Rahmanian, Software Engineer at Collective Health, gave a great introduction to actors, Akka, zio-actors and showed how modern functional effect systems like ZIO allow a reimagining of the actor paradigm in ways that increases type safety, enables coordination of state changes across multiple actors, and still preserves the benefits that brought developers to the actor paradigm.
ZIO based execution engine
In his talk, ‘A tour of String diagrams and Monoidal categories,” Juan Pablo Romero,
Software Engineer from Apple described what String diagrams are, how they relate to Monoidal categories and present a Scala declarative DSL inspired by such concepts. He showcased two interpreters – a GraphViz based renderer and a ZIO based execution engine.
Enhancing Spark’s Power with ZIO
Combining ZIO/Future with Spark can drastically speed up your ML projects’ performance, as data sources can be fetched in parallel without holding up computation. ZIO is much better than the Future, but it can be challenging to set up. Leo Benkel, Data Engineer, showed some benchmark results and explained how his open-source library handles all boilerplate issues to implement Spark and ZIO in Machine Learning projects quickly.
Microservices – from Kafka to ZIO
Let’s start by saying that Wix.com has 1500 microservices in Scala – and they moved all of them from Kafka to ZIO.
Kafka is the bedrock of Wix’s distributed microservices’ system. In the last 5 years, we have learned a lot about successfully scaling our event-driven architecture to roughly 1500 microservices, mostly written in Scala. We’ve managed to achieve higher decoupling and independence for our various services and dev teams with very different use-cases while maintaining a single uniform infrastructure in place. Our Kafka infrastructure is called Greyhound and was recently wholly re-written using ZIO.Natan Silnitsky, Backend Infrastructure Developer Wix.com
In his blog post on Medium, he also mentioned that he loves coding with ZIO, especially when it comes to concurrent/asynchronous programming.
From my experience, it is a real joy to write code with ZIO, especially in cases where you have complex concurrent/async requirements, which are much simpler to implement with the features this library provides.
In one of his posts, he also mentioned one of ZIO’s most significant benefits – lowering the entry barrier for functional programming.
But until ZIO entered the scene, the entry barrier felt too daunting (i.e., tagless final with all those boiler plate LoC just to get some custom composable effects to work with).
ZIO definitely looks much more straight forward than tagless final, including easy interop with Future, Try, and Option, simplified dependency on external resources, and better tracing capabilities
Analyst productivity improvement & Real-time Event Stream Pattern Matching for DHL
Analyst productivity improvement
Ziverge is a software development company run by John De Goes. Their client DHL needed a platform for running streaming analytics on event streams coming from a diverse set of sources. The requirement was for analysts to specify queries using a mixture of SQL and domain-specific constructs. For this platform, Ziverge chose a combination of Flink for SQL-based stream processing and ZIO Streams for the required integrations with data sources. The platform is used day-to-day intensively by several groups of analysts, resulting in massive productivity gains through the use of the familiar SQL language and the resilience of ZIO Streams as the integration technology.
Real-time Event Stream PatternPatter
The second project that ZiIverge developed for DHL resulted in a dramatic reduction in infrastructure costs.
DHL suffered from performance degradation on a legacy Python application, written to match patterns against high-throughput Kafka-based event streams. The application was rewritten in Scala using a combination of Kafka Streams and ZIO Streams components, achieving 5x per-core performance improvements compared to the previous implementation. These improvements translated directly to a reduction in infrastructure costs.
And what does DHL as a client think about ZIO?
Last year, we started using ZIO as a superior alternative to tagless-final and Monad transformers. ZIO is a powerful monad with many combinators, interop with essential libraries, and new integrations with OpenTracing and logging. ZIO lets us focus on our business logic, making it easier to understand and test. There is no doubt ZIO will be one of the significant parts of Scala infrastructure over the coming years!Jan de Groot, DHL Parcel Netherlands – Head Of Development
What’s in ZIO for programmers and the business?
Why is ZIO so good for business?
- ZIO’s high-performing scalable applications mean much better performance.
- Its resource-safe apps never leak resources, including threads, even when they fail.
- The full power of ZIO’s type-safe Scala compiler can catch bugs at compile time.
- ZIO’s test services are injected into apps, making for fast, deterministic, and type-safe testing.
- ZIO’s concurrency means apps without deadlocks, race conditions, or complexity.
- Its resilience means apps that respond to failures locally and flexibly and never lose errors.
- ZIO’s sequential code looks the same whether asynchronous or synchronous
- Its functional, simple building blocks provide rapid solutions to complex problems.
Why is ZIO good for developers?
- Purely-functional design.
ZIO allows a developer to build highly composable applications from small building blocks, thanks to its purely-functional design.
- Easy to start working with.
ZIO is excellent for introducing developers to functional programming in Scala, without the need to learn a lot of jargon and hard-to-understand concepts that are typical of other libraries like cats or Scalaz.
- Catch bugs at compile time.
Thanks to ZIO’s type safety, a developer can use the Scala compiler’s power to catch bugs at compile time. This is great because you don’t have to wait for an application to run in production to see weird bugs. After all, if your application is incorrect, it just won’t compile. Something important to notice here is that type safety is a feature of Scala itself and not exclusive to ZIO, but ZIO uses the type system’s full power. You can see at the type level if a program can fail or succeed, or if it can’t fail, or if it can’t succeed, or if it never ends. You don’t have that ability in other libraries like cats-effect or Monix.
- Write unit tests easier.
ZIO makes applications more testable, so it’s a lot easier to write unit tests.
- Refactoring that you can like.
- Refactoring ZIO code is a delight; you don’t have to worry about changing your program’s behavior while you do it.
- Build highly concurrent applications.
- Last but not least – functional programming is in demand!
How can I contribute?
Now is an excellent time to get involved in the ZIO community! If you’re a ZIO rookie, read the How to page to get started.
There are two basic ways you can help ZIO evolve:
- Participate in the development of ZIO.
The ZIO community welcomes contributors, including first-timers. It has already benefited from developers from all over the world who committed their code on GitHub. For guidance and knowledge exchange, there is an active Discord Channel. There are many ways to help that don’t require years of experience, so don’t hesitate – just try.
If you are already a ZIO contributor… high five and welcome to the club! 🙌🏻
So if you need mentoring, training, or just want to talk ZIO (no strings attached!), then you’re in the right place. Drop us a line at email@example.com or use our on-page chat to let us know we’ve got a ZIO lover on the other side. 👇🏻
- Give feedback.
Tell us if something blocks you or if something is missing that would make ZIO perfect for your project.
Thank you for reading!
If you’d like to get updates on our experiences with ZIO, follow us on Twitter. You can also find our previous blog posts about ZIO on our blog, the talks we gave at conferences, and open-source projects we’re involved in.
If anything is unclear, or you have some questions, please comment down below.
Flink-based Analyst Workbench