Zionomicon

Master the dark art of creating scalable, type-safe, concurrent apps with ZIO

feature

About

ZIO is a new Scala library that helps you rapidly build resilient and efficient concurrent apps that are easy to understand and test, and which don’t leak resources, deadlock, or lose errors.

Now ZIO creator John A. De Goes has teamed up with core contributor Adam Fraser to deliver the ultimate guide to making you a concurrent programmer of extraordinary power.

In a single book that you can work through in just 4 weeks, Zionomicon will give you the in-demand skills to excel at one of the fastest growing libraries in the Scala ecosystem.

"ZIO is a pragmatic but no-compromise tool to architect, modify, and test my software in a way that feels like Lego blocks. It makes my job more fun and helps me suffer less."

Aris Vlasakakis Credit Karma

"Last year, we started using ZIO, as a superior alternative to tagless-final and Monad transformers. ZIO is a powerful effect monad with a lot of combinators, interop with important libraries, and new integrations with OpenTracing and logging. ZIO allowed us to focus on our business logic, making it easier to understand and test, and there is no doubt ZIO will be of the significant parts of Scala infrastructure over the coming years!"

Jan de Groot DHL

"ZIO dramatically improved the structure, clarity, and performance of our code."

Jeremy Smith Netflix

Why Zio

ZIO is an innovative and next-generation library

for rapidly building modern applications that are highly-concurrent, efficient, asynchronous, and fully testable.

ZIO applications don’t leak resources, they don’t deadlocks, and they don’t lose errors. Leveraging the power of Scala’s type system, ZIO applications are correct-by-construction, with statically-verified error behavior, requiring less work and fewer tests to achieve a given level of application quality.

About ZIO

ZIO applications don’t leak resources, they don’t deadlocks, and they don’t lose errors. Leveraging the power of Scala’s type system, ZIO applications are correct-by-construction, with statically-verified error behavior, requiring less work and fewer tests to achieve a given level of application quality.

Highlights

Easy

Learn ZIO with a highly-accessible, friendly writing style that beginners love, with no confusing jargon and no requirements beyond a working knowledge of Scala.

Concurrency

Become a concurrency wizard overnight, able to ship deadlock-free, asynchronous, highly-concurrent code, powered by transactions and cancelable conditions.

Error Management

Learn how to use ZIO to statically enforce error behavior, how to sandbox defects at the edge of your application, and how to diagnose problems in production.

Resource Safety

Learn how to create applications that never leak resources, whether those resources are files, web sockets, queues, threads, database or queue connections, or even fibers.

Streaming

Learn how to build massively concurrent, high-performant streaming applications expressed using compact, beautiful, declarative, and reactive data pipelines.

Architecture

Learn how to design compositional, modular, and testable architecture for ZIO applications using layers and type-inferred dependency injection powered by the Scala compiler.

Testing

Learn how to easily and robustly test concurrent and time-based code with ZIO’s powerful testkit, with solutions for flakiness, platform-specific customizations, and more.

Comprehensive

Learn ZIO with a highly-accessible, friendly writing style that beginners love, with no confusing jargon and no requirements beyond a working knowledge of Scala.

Practical

Learn the practical side of functional Scala from a book that deliberately avoids category theory and fancy Scala features, focusing on pragmatic solutions to real world problems.

Authoritative

Written by the creators of ZIO and ZIO Test, Zionomicon contains insider-knowledge of how to get the most from ZIO—knowledge you simply can’t get anywhere else.

Skill-Building

Every chapter is packed with exercises that gradually build on each other, giving you a chance to build real skills that are immediately useful to your day job.

Affordable

Until now, the only way to get help with the ZIO library has been highly expensive workshops. Zionomicon brings mastery of ZIO within the reach of anyone, anywhere.

Topics

In depth treatment of aspects of ZIO, from essentials for getting started to concurrency and concurrent data structures, resource handling, dependency injection, and software transactional memory. Includes treatment of streaming and testing as well. Each chapter comes with clear learning goals, exercises, and worked examples so you get the most out of it.

  • About the book
  • Foreword: Why ZIO?
  • Introduction to ZIO
  • Benefits
    • Concurrency
    • Asynchronicity
    • Resource-Safety
    • Thread Management
    • Error Management
    • Dependency Management
    • Type-safety
    • Functional Programming
      • Basic functional programming concepts
        • Pure functions
        • Referential transparency
        • Side effects versus effects
      • Benefits of functional programming
        • Better ability to reason about programs
        • Ability to reason about all parts of a program in the same way
        • Description vs execution
        • Ability to control the effectful programs
  • Competitive Landscape
    • Future
    • Cats Effect
    • Akka
  • Learning Goal
  • Essentials
  • ZIO effects are workflows, they describe things. Effects as values, programs as values, program that does a bunch of things versus program as value. Need to hammer home that point.
  • Mock up graphics, don’t need to be pretty
  • 02 - First Steps with ZIO
    • Basic model of ZIO[R, E, A] as a function R => Either[E, A] - need to walk through this, not superficial
    • Meaning of each type parameter
    • Subtypes of ZIO (e.g. IO, UIO)
    • Effect constructors
    • Comparison to Future
    • Use of standard environmental effects
    • Learning Goal: Readers should be able to create sequential effects with flatMap, zip, etc., understand for comprehensions,
    • Learning Goal: Readers should be able to make side effecting programs functional by “lifting” effects into ZIO.
  • 03 - Next Steps With ZIO
    • Using recursion to model programs that repeat or continue forever
    • Importing asynchronous effects into ZIO
  • 04 - Testing ZIO Programs
    • Writing simple tests with ZIO Test
    • Using assertions
    • Test implementations of standard environment types
    • Common test aspects
    • Basic property based testing
    • Learning Goal: Readers should be able to read and write tests for ZIO programs.
  • 05 - The ZIO Error Model
    • Common error handling combinators
    • Basic retrying
    • Checked versus unchecked exceptions
    • Exposing and submerging the full cause
    • Exit as the full result of a computation
    • Parallel and sequential errors
    • Tracing
    • Learning Goal: Users should be able to use error handling combinators to move results between the value and error channels as necessary.
  • 06 - Integrating with ZIO
    • Integrating with Java
    • Integrating with Javascript
    • Integrating with Cats Effect
    • Integrating with Specific Libraries (Doobie, http4s)
    • Learning Goals: Readers should be able to use existing libraries that are not built on ZIO in their ZIO programs.
  • Concurrency & Parallelism
  • 07 - The Fiber Model
    • Fibers distinguished from operating system threads
    • Forking Fibers
    • Joining Fibers
    • Interrupting Fibers
    • Fiber Supervision
    • Locking effects
    • Learning Goal: Users should be able to use fibers to implement simple parallelism and concurrency operations (e.g. performing two effects in parallel an combining the results)
  • 08 - Parallelism
    • Parallelism combinators as preferred tools for solving common parallelism problems
    • Race and zipPar as expressing fundamental concepts of “both” and “either
    • Combinators built on top of these (e.g. foreachPar, collectAllPar, raceAll).
    • Bounded parallelism combinators
    • Other variants (e.g. validatePar)
    • Learning Goal: Readers should be able to competently use parallel versions of sequential operators, including variations that allow bounded parallelism.
  • 09 - Fiber Supervision in Depth
    • Fork/Join Identity Law
    • Structured Concurrency
    • Custom Supervison Strategies
    • Fire and Forget
    • Learning goal: Readers should be able to implement advanced concurrency combinators that require fine grained control over fiber lifetimes
  • 10 - Interruption in Depth
    • Interruptible and uninterruptible regions
    • InterruptibleMask and unInterruptibleMask
    • Composing Interruptibility
    • Waiting for interruption
    • Learning Goal: Readers should be able to implement their own combinators that create precisely defined interruptible and uninterruptible regions, including reimplementing combinators such as bracket
  • Concurrent Structures
  • 11- References: Functional Descriptions of Mutable State
    • Ref as functional version of an atomic reference
    • Operations are atomic, but do not compose atomically
    • Using Refs to share state between fibers
    • RefM for evaluating effects while updating
    • FiberRef for state locally scoped to a fiber
    • Learning Goal: Readers should be able to use Refs to share state between fibers and replace mutable variables with immutable Refs
  • 12 - Promise: Work Synchronization
    • Promise as a functional version of a promise
    • Various ways of completing promises (e.g. with values versus effects)
    • Waiting on a promise
    • Promises and interruption
    • Combining Ref and Promise for more complicated concurrency scenarios
    • Learning Goal: Readers should be able to combine Ref and Promise to implement more sophisticated concurrency concepts such as a cache
  • 13 - Queue: Work Distribution
    • Queues as generalizations of promises
    • Offering and taking values from a queue
    • Varieties of queues (e.g. bounded, unbounded)
    • Learning Goal: Readers should be able to use queues to implement even more advanced concurrency concepts such as actors
  • 14 - Hub: Broadcasting
    • Hub an optimal solution to broadcasting problem
    • Creating Hubs
    • Operators on Hubs
  • 15 - Semaphore: Work Limiting
    • Semaphore Interface
    • Using semaphore to limit parallelism
    • Using semaphore to implement operators
    • Making a data structure safe for concurrent access
    • Learning Goal: Readers should be able to use semaphores to limit access to some scarce resources.
  • Resource Handling
  • 16 - Acquire Release: Safe Resource Handing
    • The limitation of try-finally in asynchronous programming
    • Acquire Release as a generalization of tye and finally
    • The ensuring operator
  • 17 - Scope: Composable Resources
    • Reification of acquire release
    • Scope as a dynamic scope
    • Constructing scoped resources
    • Transforming scoped resources
    • Varieties of scoped resources
    • Learning Goal: Readers should be able to implement concurrent programs that guarantee resources will be released as early as possible
  • 18 - Advanced Scopes
    • Scopes revisited
    • From scopes to resources
    • Using resources
    • Child scopes
    • Putting it all together
  • Dependency Injection
  • 19 - Essentials
    • Limitations of traditional functional dependency injection approaches, including Tagless Final, ReaderT, and implicits
    • ZIO as reader monad on steroids
    • Accessing the environment
    • Composition of environment types
    • Providing an effect with its required environment
    • Learning Goals: Readers should be able to access environmental in their programs and provide programs with their required environment
  • 20 - Advanced
    • What is ZEnvironment?
    • Providing multiple services of the same type
    • Handling errors in layer construction
    • Meomization of dependencies
    • Automatic ZLayer derivation
    • Learning Goals: Readers should be able to handle more complex dependency injection scenarios
  • Software Transactional Memory
  • 21 - STM: Composing Atomicity
    • Inability to compose atomic actions with other concurrency primitives
    • Conceptual description of STM
    • Using STM
    • Limitations of STM
    • Learning Goal: Readers should be able to recognize problems requiring STM and use existing combinators to solve them
  • 22 - STM Data Structures
    • Description of STM data structures
    • Common operations
    • Creating STM data structures from existing ones
    • Learning Goal: Readers should be able to create their own STM data structures to solve problems in their domain
  • 23 - Advanced STM
    • Debugging
    • Optimization
    • Effects
    • Learning Goal:
  • Advanced Error Management
  • 24 - Retries
    • Retrying and repeating with ZIO
    • Common schedules
    • Composing schedules
    • Implementation of schedule
    • Learning Goal: Readers should be able to use existing schedule combinators to create rich repeat and retry logic for their applications
  • 25 - Debugging
    • Execution traces
    • Fiber dumps
    • etc.
    • Learning Goal: Readers should be able to figure out why an app is failing to make progress (where it is getting stuck) and to be able to retrieve full diagnostic information for any failure.
  • 26 - Best Practices
    • Recoverable errors
    • Non-recoverable errors
    • Sandboxing at edge
    • Logging errors
    • Etc.
  • Streaming
  • 27 - First Steps with ZStream
    • Streams as collections
    • Constructing basic streams
    • Running streams
    • Type parameters
  • 28 - Next Steps with ZStream
    • Sinks
    • Pipelines
  • 29 - Channels: Unifying Streams, Sinks, and Pipelines
    • Channels
    • Channel constructors
    • Channel operators
    • Channel scopes
  • 30 - Transforming Streams
    • Stateful and concurrent mapping
    • Transform and compbine
    • Flattening
    • Filtering operators
    • Collecting (filter-map)
    • Grouping
    • Partitioning
    • Broadcasting and distributing
    • Flow control and rate limiting (Buffering, Debouncing and Throttling)
    • Learning Goal: Readers should be familiar with the many operators for transforming streams.
  • 31 - Combining Streams
    • Stream concatenation
    • Merging streams
    • Zipping streams
    • Cartesian product
    • Fallback streams
    • Stateful stream combination
    • Interleaving
    • Learning Goal: Readers should be familiar with the many operators for combining streams, especially concurrent operators.
  • 32 - Pipelines
    • Pipelines as stream transformation
    • Using pipelines
    • Constructing pipelines
    • Learning Goal: Readers should be familiar with built-in pipelines and know how to create their own custom transducers that work efficiently on chunked data.
  • 33 - Sinks
    • Sinks a composable aggregation strategies
    • Using sinks
    • Combining sinks
    • Constructing sinks
    • Learning Goal: Readers should be familiar with built-in sinks and know how to create their own sinks that involve resource handling.
  • Basic Testing
  • 34 - Overview
    • Tests as effects
    • Specs as recursively nested collections of tests
    • Learning Goal: Readers should be able to use the structure of tests as effects to reimplement basic combinators such as timing out a test or making sure that a test is not flaky
  • 35 - Assertions
    • Assertions as predicates
    • Common ZIO assertions
    • Smart assertions
  • 36 - The Test Environment
    • Test implementation of standard services
    • Accessing the Live environment
    • Creating custom test implementations
    • Learning Goal: : Readers should be able to modify the test environment as needed (e.g. using the live clock or a clock that passes time at an accelerated rate).
  • Advanced Testing
  • 37 - Test Aspects
    • Test aspects as encoding of universally quantified functions
    • Ability to constrain types
    • Common test aspects
    • Implementing test aspects
    • Repeating and retrying tests
    • Learning Goal: : Readers should be able to identify transformations to tests that could be achieved with test aspects and implement them
  • 38 - Using Resources in Tests
    • Providing resources to tests
    • Sharing resources between test iterations
    • Providing resources to test suites
    • Sharing resources between tests
    • Composing resources together and extending the TestEnvironment
    • Learning Goal: : Readers should be able to implement a custom environment needed for their tests, create an enriched version of the TestEnvironment including their environment, and provide it to their tests
  • 39 - Property Based Testing
    • Representation of a generator as an effectual stream of samples
    • Random and deterministic generators
    • Samples and shrinking
    • Generator combinators
    • Learning Goal: Readers should be able to implement their own generators including custom shrinking logic
  • 40 - Test Annotations
    • Test annotations as ways to record additional information about tests
    • Implementing test annotations
    • Implementing test annotation reporters
    • Learning Goal: Readers should be able to implement and use their own test annotations
  • 41 - Reporting
  • Applications (100 pages)
  • 42 Parallel Web Crawler
  • 43 File Processing
  • 44 Command-Line Application
  • 45 Kafka Stream Processor
  • 46 gRPC Microservices
  • 47 REST API
  • 48 GraphQL API
  • 49 Spark
Readers will understand the purpose of functional effects and be able to defend deploying ZIO in a new or existing project where the requirements align with the feature set of ZIO.

About the authors

John A. De Goes

A mathematician by training but a software engineer by vocation, John A. De Goes has been professionally writing software for more than 30 years. John is an internationally recognized expert on functional programming, is an avid speaker and OSS contributor, and is the original author and architect of ZIO.

Adam Fraser

Is a software engineer who is passionate about using the power of functional programming to solve hard business problems. Adam is one of the top contributors to ZIO, the co-author of ZIO Test, and the author of ZIO Query, as well as a regular conference speaker, writer, and mentor.