Serverless computing enables developers to concentrate solely on their applications rather than worry about where they've been deployed. With the Ray general-purpose serverless implementation in Python, programmers and data scientists can hide servers, implement stateful applications, support direct communication between tasks, and access hardware accelerators.
In this book, experienced software architecture practitioners Holden Karau and Boris Lublinsky show you how to scale existing Python applications and pipelines, allowing you to stay in the Python ecosystem while reducing single points of failure and manual scheduling. Scaling Python with Ray is ideal for software architects and developers eager to explore successful case studies and learn more about decision and measurement effectiveness.
If your data processing or server application has grown beyond what a single computer can handle, this book is for you. You'll explore distributed processing (the pure Python implementation of serverless) and learn how to:
• Implement stateful applications with Ray actors
• Build workflow management in Ray
• Use Ray as a unified system for batch and stream processing
• Apply advanced data processing with Ray
• Build microservices with Ray
• Implement reliable Ray applications
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# Scaling Python with Ray: Adventures in Cloud and Serverless Patterns
## 【One-Line Pitch】
A practical guide for Python developers and architects who need to scale applications beyond a single machine, showing how Ray provides a unified serverless framework for distributed computing, stateful actors, streaming, and microservices—all while staying in the Python ecosystem.
## 【Book Arc】
- **Opening (~0%–10%)**: Introduces Ray's position in the distributed computing landscape, comparing it to cluster orchestrators (Kubernetes, Slurm), parallelization frameworks (multiprocessing, Celery), and data processing tools (Spark, Dask). Establishes Ray as a "distributed glue" framework with a unified API for traditionally separate problems.
- **Early (~10%–25%)**: Covers Ray installation, local mode setup, and the fundamentals of remote functions—the core building block for parallel execution. Includes practical examples of parallelizing slow functions, handling task dependencies, and the critical distinction between passing ObjectRefs directly versus inside Python structures.
- **Early (~25%–34%)**: Deepens into task composition patterns: using `ray.get` versus `ray.wait` for result collection, avoiding deadlocks, and implementing nested parallelism for recursive algorithms and hyperparameter tuning with parallel model training.
- **Middle (~34%–44%)**: Introduces Ray actors for stateful applications, covering actor lifecycle, handles, and persistence strategies—from simple filesystem storage to more robust patterns using Ray's object store. Includes a detailed bank account example demonstrating state recovery.
- **Late (~44%–60%)**: Explores Ray's design internals: object management, reference counting, serialization with cloudpickle, and custom serializers for classes with nonserializable components. Covers fault tolerance, actor retries, and the implications of detached resources on cluster scaling.
- **Ending (~60%–100%)**: Moves to advanced topics: Apache Arrow integration, vertical scaling with resources, autoscaling, placement groups, namespaces, runtime environments, and the Ray Job API for deployment. Concludes with streaming applications using Kafka and building reliable, production-ready Ray systems.
## 【Key Takeaways】
- **Ray as a general-purpose serverless platform** (Early): Unlike function-as-a-service offerings, Ray provides a foundation for stateful applications, direct task communication, and hardware accelerator access—making it suitable for a broader range of distributed computing problems than typical serverless implementations.
- **Remote functions are the fundamental abstraction** (Early): The `@ray.remote` decorator transforms any Python function into a distributed task, with `ray.get` and `ray.wait` providing control over result collection. Using `ray.wait` prevents deadlocks and enables processing results as they become available, which is essential for production workloads.
- **ObjectRefs must be passed directly to functions** (Early): Ray only resolves ObjectRefs passed as direct arguments—wrapping them in lists, dictionaries, or classes breaks dependency tracking and causes type errors. This subtle constraint shapes how you design task composition and data flow.
- **Actors enable stateful distributed applications** (Middle): Actor handles provide a reference to stateful objects that persist across method calls, with method invocation being faster than remote functions since no resource allocation is needed per call. However, actor state is lost when handles go out of scope unless you implement persistence.
- **Persistence requires explicit design** (Middle): The book demonstrates filesystem-based state storage and recovery patterns for actors, showing that while Ray manages distribution, developers must implement their own state durability—a critical consideration for production systems.
- **Serialization is a hidden complexity** (Middle): Ray uses cloudpickle for serialization, which handles more cases than Python's built-in pickle but still fails on nonserializable components like database connections or thread pools. Custom serializers using `__getstate__`/`__setstate__` can work around these limitations by storing reconstruction information.
- **Reference counting affects memory management** (Middle): Ray uses reference counting for object lifecycle, which is susceptible to circular references. Setting objects to `None` when done and using `ray memory --group-by STACK_TRACE` to diagnose leaks are practical techniques for managing distributed memory.
- **Ray integrates with, rather than replaces, specialized tools** (Early): While Ray can handle a bit of SQL or key/value storage, it's not designed to replace specialized systems. The pragmatic approach is using Ray as a distributed glue layer that orchestrates other frameworks like Spark, Dask, or Modin running on Ray.
## 【Reading Tips】
- **Skim Chapter 1–2 for context, deep-read Chapter 3**: The early chapters establish Ray's positioning and basic setup, but the remote function patterns (dependency passing, `ray.wait` vs `ray.get`, nested parallelism) are the foundation everything else builds on—worth careful study with the code examples.
- **Pay special attention to the "broken" examples**: The book deliberately shows code that fails (like passing ObjectRefs in a list), and these negative examples teach the mental model of how Ray tracks dependencies more effectively than the working versions.
- **Focus on the actor persistence patterns**: The bank account example spanning multiple chunks shows the evolution from simple to robust state management. Understanding this progression is key to designing production-grade stateful applications.
- **The later chapters on Ray internals are reference material**: Object management, serialization, and reference counting are important for debugging and optimization, but you can skim initially and return when you encounter specific issues in your own applications.
- **Skip the Kafka streaming details if not relevant**: The streaming chapter is application-specific; the general patterns for scaling and key-based approaches are useful, but the Kafka API details are only necessary if you're building stream-processing systems.
## 【Coverage Limits】
This guide covers the book's first half in depth (through Ray design details and object management). The later sections on advanced data processing, microservices, and reliability patterns are only briefly mentioned based on the table of contents; the excerpts do not provide sufficient detail to summarize those chapters' specific techniques.
##
Excerpt 1
27 Ray Remote Best Practices 30 Bringing It Together with an Exa...
blem that needs a bit of SQL, or some non-Python libraries, Ray cannot meet your needs—you just may need to bring in additional tools. Conclusion Ray has the...
nd how to use ray.wait to prevent dead‐ locks in your code. Finally, you learned about remote function composition and how to use it for rudi‐ mentary execut...
erence counting makes it especially important when defining objects to set them to None when you are done with them or make sure they go out of scope. Ray’s ...
key is not defined, it uses round-robin partitioning, dis‐ tributing the topic’s messages equally across partitions; if the key is defined, the partition to ...
ailable for deployments. Additional Deployment Capabilities Additional deployment capabilities are provided in three ways: • Adding parameters to annotations...
from method calls and receive externally triggered events. You can use virtual actors to add state to an otherwise stateless workflow. Ray Workflows Features...
tion_filter=None # Since the file doesn't end in .csv ) At present, the protocol is incorrectly stripped off, so you need to put it in twice. For example...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Scaling Python with Ray Adventures in Cloud and Serverless Patterns (Holden Karau, Boris Lublinsky) (Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Scaling Python with Ray Adventures in Cloud and Serverless Patterns (Holden Karau, Boris Lublinsky) (Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment