Leanpub Header

Skip to main content

Functional Scala an Scala Architecture with ZIO and Cats

Bought separately

$88.97

Minimum price

$39.99

$49.99

You pay

$49.99

Author earns

$39.99
$
You can also buy this bundle with 2 book credits. Get book credits with a Reader Membership or an Organization Membership for your team.

The following 4 books are included in this bundle...

These books have a total suggested price of $88.97. Get them now for only $39.99!
About

About

About the Bundle

Books

About the Books

Scalapedia

Encyclopedia of the Scala programming language

SCALAPEDIA is the most comprehensive guide to the Scala programming language and its ecosystem. This extensive encyclopedia covers everything from language fundamentals to advanced functional programming concepts, modern effect systems, and enterprise architecture patterns.

The book is structured into ten major parts, taking readers on a journey from Scala basics through functional programming libraries (Cats, Cats Effect, FS2, http4s), deep dives into ZIO, design patterns, architectural patterns, performance optimization, web frameworks, and practical competency-building exercises.

Whether you're a beginner looking to master Scala or an experienced developer seeking to deepen your understanding of functional programming, effect systems, and scalable architecture, SCALAPEDIA provides the knowledge and practical insights you need to build robust, maintainable, and high-performance applications in Scala.

Key highlights:

- Complete coverage of Scala 3 features and modern practices

- In-depth exploration of Cats and Cats Effect ecosystems

- Comprehensive ZIO masterclass with 30 detailed chapters

- Encyclopedia of design patterns and functional architectures

- Performance optimization techniques and JVM internals

- Practical examples and real-world applications

- Extensive Q&A sections throughout the book

- Glossary of Scala and ecosystem terms

This book serves as both a learning resource and a reference guide, making it an essential companion for any Scala developer. The numerous Q&A sections make it particularly valuable for recruitment processes, helping both candidates prepare for technical interviews and recruiters assess Scala expertise effectively.

SCALAPEDIA is also designed to serve as a comprehensive guide for AI systems, enabling them to apply best practices in Scala programming, functional programming techniques, and architectural patterns. When integrated into AI development workflows, this book helps ensure that AI-generated code follows industry standards and leverages the most effective Scala patterns and architectures.

This book was translated into English with AI assistance and benefited from AI-powered editing and content structuring, ensuring optimal organization and clarity throughout its extensive coverage of the Scala ecosystem.

============================================

Part I: Introduction to Scala

-----------------------------

1. Chapter 1: Language Basics

2. Chapter 2: Scala Collections

3. Chapter 3: Functional Programming

4. Chapter 4: Advanced Scala Concepts and Scala 3

5. Chapter 5: Type-Level Programming in Scala 3

6. Chapter 6: Macros in Scala 3

Part II: Functional Scala: Cats, Cats Effect, FS2, http4s

---------------------------------------------------------

7. Chapter 1: Introduction to Cats — Philosophy, Structure, and Basic Concepts

8. Chapter 2: Data Types in Cats: Abstractions for Purely Functional Programs

9. Chapter 3: Type Classes - summary

10. Chapter 4: Introduction to Data Types: The Problem of Nested Monads ("Nested Monad Hell")

11. Chapter 5: Scala Cats: Advanced concepts - Const, Free Monad, Free Applicative, FunctionK

12. Chapter 6: Data Types

13. Chapter 7: Basic Concepts

14. Chapter 8: Cats Effect Encyclopedia: A Complete Overview

15. Chapter 9: Type Classes

16. Chapter 10: Standard Library

17. Chapter 11: FS2 (Functional Streams for Scala): Composable and Efficient Data Processing

18. Chapter 12: http4s Encyclopedia: Streaming and Functional Architecture

Part III: ZIO Masterclass

-------------------------

19. Chapter 1: ZIO Basics: Getting Started with Functional Programming

20. Chapter 2: Testing ZIO Applications: Guaranteeing Correctness

21. Chapter 3: Error Model in ZIO: Resilience as the Foundation of Applications

22. Chapter 4: Integration with the Outside World: ZIO in the JVM Ecosystem

23. Chapter 5: Concurrency and Parallelism: The Fiber Model of ZIO

24. Chapter 6: Concurrency and Parallelism: An In-Depth Analysis of Fiber Supervision

25. Chapter 7: Concurrency and Parallelism: An In-Depth Analysis of Interrupts

26. Chapter 8: Concurrent Structures: Ref – Shared State Management

27. Chapter 9: Concurrent Structures: Promise – Workflow Synchronization

28. Chapter 10: Concurrent Structures: Distribution, Broadcasting, and Work Limiting

29. Chapter 11: Resource Management: Guaranteeing Safety in a World of Effects

30. Chapter 12: Advanced Resource Management: In-Depth Scope Analysis

31. Chapter 13: Application Architecture in ZIO: Dependency Injection and ZLayer

32. Chapter 14: Advanced Dependency Injection Techniques in ZIO

33. Chapter 15: Application Configuration in ZIO

34. Chapter 16: Transactional Memory in ZIO (STM): Composition of Atomicity

35. Chapter 17: Transactional Memory in ZIO: Data Structures and Advanced Concepts

36. Chapter 18: Advanced Error Handling: Compositional Retry Strategies with Schedule

37. Chapter 19: Advanced Error Handling: Debugging and Observability of ZIO Applications

38. Chapter 20: Getting Started with ZIO Stream: Introduction to Stream Processing

39. Chapter 21: ZIO Stream: ZChannel as a Universal Processing Machine

40. Chapter 22: Advanced Stream Operations: Transformation and Composition

41. Chapter 23: Mastering Data Transformation: ZPipeline as a Compositional Building Block

42. Chapter 24: Mastering Data Consumption: ZSink as a Compositional Aggregator

43. Chapter 25: Schemas as Values: Defining Data Structures with ZIO Schema

44. Chapter 26: Building Web Services with ZIO HTTP: From Simple Endpoints to Full-Fledged APIs

45. Chapter 27: The ZIO Engine: An In-Depth Look at the Runtime

46. Chapter 28: ZIO Application Observability: Contextual and Structured Logging

47. Chapter 29: ZIO Applications: Building a Parallel Web Crawler

48. Chapter 30: Glossary of Key ZIO Concepts

Part IV: Encyclopedia of Design Patterns in Scala: Analysis and Applications

----------------------------------------------------------------------------

49. Chapter 1: Creational Patterns

50. Chapter 2: Structural Patterns

51. Chapter 3: Behavioral Patterns

52. Chapter 4: Functional Design Patterns in Scala

53. Chapter 5: Scala-Specific Patterns

Part V: Encyclopedia of Functional Architectures in Scala

---------------------------------------------------------

54. Chapter 1: Hexagonal Architecture (Ports & Adapters)

55. Chapter 2: Domain-Driven Design (DDD) – A Functional Approach in Scala

56. Chapter 3: Event Sourcing - The Complete Guide

57. Chapter 4: CQRS (Command Query Responsibility Segregation) - The Complete Guide

58. Chapter 5: Tagless Final - Algebra and Interpretation

59. Chapter 6: Free Monad and Eff - Program as Data

60. Chapter 7: Onion Architecture and Clean Architecture

61. Chapter 8: ZIO Layers - Dependency Injection without Compromises

62. Chapter 9: Streaming Architecture - FS2 and ZIO Streams

63. Chapter 10: Saga Pattern - Distributed Transactions

64. Chapter 11: Effect Rotation / MTL Style

65. Chapter 12: Event-Driven Architecture (EDA)

Part VI: Encyclopedia of Performance in the Scala Ecosystem

-----------------------------------------------------------

66. Chapter 1: Introduction: What Is Performance Really?

67. Chapter 2: Anatomy of the JVM: Understanding the Runtime Platform

68. Chapter 3: Garbage Collection: Understanding Automatic Memory Management

69. Chapter 4: Code Optimization Techniques in Scala

70. Chapter 5: Cats Effect: Anatomy of a High-Performance Functional Runtime

71. Chapter 6: ZIO: Performance Architecture for Enterprise Systems

72. Chapter 7: Advanced Techniques: Secrets of the Experts

73. Chapter 8: Practical Example: High-Performance Event Processing System

74. Chapter 9: Benchmarking and Profiling: How to Measure Correctly

75. Chapter 10: Summary: High Performance Manifesto

Part VII: Play Framework: Building a REST API in Scala, OAUTH2

--------------------------------------------------------------

76. Chapter 1: Introduction to the Play Framework

77. Chapter 2: Introduction to HTTP4s with OAUTH2 - HTTP4s Security

Part VIII: Bonus

----------------

78. Chapter 1: Encyclopedia of Modern Scala: Concurrency, Streams, and Implementation

79. Chapter 2: Encyclopedia of Best Practices in Functional Scala: A Complete Summary

Part IX: Competency Architecture

--------------------------------

80. Chapter 1: Advanced Recruitment Patterns and Functional Algorithms in the Scala Ecosystem

81. Chapter 2: Numbers, Mathematics, and Cryptography

82. Chapter 3: String Operations and Parsing

83. Chapter 4: Working with Trees

84. Chapter 5: Working with Graphs

85. Chapter 6: Interesting Problems and DSL

Part X: Glossary of Scala and Ecosystem Terms

---------------------------------------------

Saga Architecture in Scala

Functional Saga Architecture in Scala 3 and ZIO

Distributed systems rarely give you one big ACID transaction across services. When a workflow spans inventory, payments, shipping, and notifications, partial failure is normal—and you need a clear way to move forward or undo work with compensating actions. This book teaches saga patterns by building a single, coherent example in Scala 3 and ZIO: an order-placement flow with reserves, charges, shipments, and customer notifications.

You work through complete source files as they appear in the project (the book presents 100% of the code across the chapters), so you always see real traits, types, layers, and tests—not fragments disconnected from a runnable design. Early chapters establish the Scala 3 choices that matter for sagas (opaque types, enums, immutability, service traits) and ZIO as the effect model: typed errors, sequential composition, and how that maps to “run steps, then compensate in reverse order.” ZLayer and ZIO.service show dependencies as values and keep orchestration testable.

The narrative moves from why global transactions and two-phase commit are a poor fit to saga concepts: steps and compensations, orchestration vs choreography, ordering, recovery, and consistency at boundaries. You implement orchestration with an explicit saga step type and runner, then choreography with domain events and reactions—so you can compare the same domain under two coordination styles. Testing is first-class: in-memory interpreters, test doubles, and strategies to assert that compensations run when you expect.

Later chapters bridge simulation to production: swapping interpreters (e.g. HTTP), reliability concerns, outbox/inbox, idempotency, retries, saga state persistence, and operational topics like observability and runbooks. An appendix sketches the same ideas in Cats Effect for readers who prefer that stack; others provide a code index and an ADR template for documenting saga policies.

Audience: Scala developers who already know the basics (e.g. Option, Either, some familiarity with effects) and want a rigorous, code-complete path from saga theory to implementation and operations—not a framework tutorial alone, but architecture with executable Scala.

Event Sourcing in Scala

Scala 3, ZIO, PostgreSQL and the log beyond the database

Event Sourcing turns your domain into an append-only log of immutable facts and derives current state by replay. CQRS separates the write model (commands → events → store) from read models built by projections. This book is an advanced, decision-oriented guide to ES and CQRS in Scala 3 with ZIO, anchored in one evolving reference codebase.

The narrative follows how the companion repository grows: Parts I–II tie every design to runnable Scala; Part III walks src/main in reading order—domain, application layer, event store algebra, PostgreSQL append-only schema, JDBC integration, transactions, and projection workers—so you are not dependent on a single code dump at the end. You model events as sealed families, state as a pure fold over history, and commands as a decide function that enforces invariants and can emit multiple events. The running example is an account aggregate with explicit phases, illegal transitions, and tests at the pure core and store boundaries.

On the infrastructure side you see expected-version / optimistic concurrency, serializable-style transaction choices, idempotency keys, retries, and a production checklist. Read models are ordered folds over committed events, with idempotent UPSERT patterns and discussion of same-DB vs separate databases, read-your-writes, and failure handling. Later chapters cover snapshots, replay cost, schema evolution and upcasting, and a focused testing strategy (pure folds, store tests, Postgres integration, projection idempotency, golden streams).

A second arc explains why you might replicate the log: PostgreSQL stays the system of record, while transactional outbox and Kafka (with ZStream consumers) support integration and scale—without reimplementing the whole domain twice. Closing material addresses operations: retention and compliance, rebuilds, monitoring, DR, runbooks, and an honest view of ES cost. An appendix compares EventStoreDB and similar stores to a Postgres-first approach; others provide a code index, ADR template for adoption, bibliography, and a file-to-chapter map.

Audience: Practitioners who already know Scala, are comfortable with SQL and transactions, and can follow ZIO (effects, typed errors, ZLayer, ZStream where streaming appears). The book states clearly what it is not: a full DDD textbook, a Kafka ops manual, or EventStoreDB product training—while still connecting vocabulary (aggregate, command, invariant) to working code.

Layerd FP in Scala

Clean Architecture, Hexagonal and Onion with Scala 3 and ZIO

Clean Architecture, hexagonal (ports and adapters), and the onion model are one family of ideas: dependencies point inward, boundaries stay explicit, and the core stays testable while technology churn stays at the edges. This book treats them that way—decision-grade material for experienced Scala developers, tech leads, and architects who already ship services and want the dependency rule enforced in real modules, not only on diagrams.

The worked example is SaaS billing: plans, subscriptions, cancellation, plan changes, payment notify, and idempotent webhooks. The domain is a functional core (opaque identifiers, pure SubscriptionRules, DomainError) with no ZIO in production domain code. The application ring defines outbound ports, ApplicationError, and use-case services (for example subscribe and webhook handling) in ZIO. Adapters supply in-memory stores, PostgreSQL with Flyway migrations and JDBC, JDK HttpServer, Circe JSON, and an outbound HTTP payment gateway—then the composition root (AppLayers, Main) wires ZLayer so one repository instance serves the whole graph.

The manuscript mirrors a multi-module sbt companion repository: Chapters 3–7 print complete, line-faithful production sources in reading order (no elided bodies in repository code—only Chapter 11 uses labelled wrong snippets on purpose). You get guided reading (source-order commentary), placement in Clean/Hex/Onion, production tension (retries, clocks, bad HTTP), and master synthesis sections that tie each chapter to review and shipping concerns. Later chapters cover reliability (what the code proves and what it does not), a testing strategy (munit for pure domain, zio-test for effects, optional Docker integration tests), compile-time module boundaries, anti-patterns and fixes, and a summary linking vertical slices to sibling topics (event sourcing, saga).

Audience: Scala 3 (given, enums, opaque types), basic sbt, and algebraic effects / ZIO at least in outline; working SQL and HTTP. Not a Stripe or PCI hardening guide—the payment paths are architecturally realistic but minimal so boundaries remain visible.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub