Elixir in Action, Second Edition

Book Description

Elixir in Action, Second Edition teaches you how to build production-quality distributed applications using the Elixir programming language. Author Saša Juric introduces this powerful language using examples that highlight the benefits of Elixir’s functional and concurrent programming. You’ll discover how the OTP framework can radically reduce tedious low-level coding tasks. You’ll also explore practical approaches to concurrency as you learn to distribute a production system over multiple machines.

Table of Contents

  1. Cover
  2. Titlepage
  3. Copyright
  4. Brief Contents
  5. Contents
  6. praise for the first edition
  7. preface
  8. acknowledgments
  9. about this book
    1. Who should read this book
    2. How this book is organized
    3. About the code
    4. Book Forum
  10. about the author
  11. about the cover illustration
  12. Chapter 1: First steps
    1. 1.1 About Erlang
      1. 1.1.1 High availability
      2. 1.1.2 Erlang concurrency
      3. 1.1.3 Server-side systems
      4. 1.1.4 The development platform
    2. 1.2 About Elixir
      1. 1.2.1 Code simplification
      2. 1.2.2 Composing functions
      3. 1.2.3 The big picture
    3. 1.3 Disadvantages
      1. 1.3.1 Speed
      2. 1.3.2 Ecosystem
    4. Summary
  13. Chapter 2: Building blocks
    1. 2.1 The interactive shell
    2. 2.2 Working with variables
    3. 2.3 Organizing your code
      1. 2.3.1 Modules
      2. 2.3.2 Functions
      3. 2.3.3 Function arity
      4. 2.3.4 Function visibility
      5. 2.3.5 Imports and aliases
      6. 2.3.6 Module attributes
      7. 2.3.7 Comments
    4. 2.4 Understanding the type system
      1. 2.4.1 Numbers
      2. 2.4.2 Atoms
      3. 2.4.3 Tuples
      4. 2.4.4 Lists
      5. 2.4.5 Immutability
      6. 2.4.6 Maps
      7. 2.4.7 Binaries and bitstrings
      8. 2.4.8 Strings
      9. 2.4.9 First-class functions
      10. 2.4.10 Other built-in types
      11. 2.4.11 Higher-level types
      12. 2.4.12 IO lists
    5. 2.5 Operators
    6. 2.6 Macros
    7. 2.7 Understanding the runtime
      1. 2.7.1 Modules and functions in the runtime
      2. 2.7.2 Starting the runtime
    8. Summary
  14. Chapter 3: Control flow
    1. 3.1 Pattern matching
      1. 3.1.1 The match operator
      2. 3.1.2 Matching tuples
      3. 3.1.3 Matching constants
      4. 3.1.4 Variables in patterns
      5. 3.1.5 Matching lists
      6. 3.1.6 Matching maps
      7. 3.1.7 Matching bitstrings and binaries
      8. 3.1.8 Compound matches
      9. 3.1.9 General behavior
    2. 3.2 Matching with functions
      1. 3.2.1 Multiclause functions
      2. 3.2.2 Guards
      3. 3.2.3 Multiclause lambdas
    3. 3.3 Conditionals
      1. 3.3.1 Branching with multiclause functions
      2. 3.3.2 Classical branching constructs
      3. 3.3.3 The with special form
    4. 3.4 Loops and iterations
      1. 3.4.1 Iterating with recursion
      2. 3.4.2 Tail function calls
      3. 3.4.3 Higher-order functions
      4. 3.4.4 Comprehensions
      5. 3.4.5 Streams
    5. Summary
  15. Chapter 4: Data abstractions
    1. 4.1 Abstracting with modules
      1. 4.1.1 Basic abstraction
      2. 4.1.2 Composing abstractions
      3. 4.1.3 Structuring data with maps
      4. 4.1.4 Abstracting with structs
      5. 4.1.5 Data transparency
    2. 4.2 Working with hierarchical data
      1. 4.2.1 Generating IDs
      2. 4.2.2 Updating entries
      3. 4.2.3 Immutable hierarchical updates
      4. 4.2.4 Iterative updates
      5. 4.2.5 Exercise: importing from a file
    3. 4.3 Polymorphism with protocols
      1. 4.3.1 Protocol basics
      2. 4.3.2 Implementing a protocol
      3. 4.3.3 Built-in protocols
    4. Summary
  16. Chapter 5: Concurrency primitives
    1. 5.1 Concurrency in BEAM
    2. 5.2 Working with processes
      1. 5.2.1 Creating processes
      2. 5.2.2 Message passing
    3. 5.3 Stateful server processes
      1. 5.3.1 Server processes
      2. 5.3.2 Keeping a process state
      3. 5.3.3 Mutable state
      4. 5.3.4 Complex states
      5. 5.3.5 Registered processes
    4. 5.4 Runtime considerations
      1. 5.4.1 A process is sequential
      2. 5.4.2 Unlimited process mailboxes
      3. 5.4.3 Shared-nothing concurrency
      4. 5.4.4 Scheduler inner workings
    5. Summary
  17. Chapter 6: Generic server processes
    1. 6.1 Building a generic server process
      1. 6.1.1 Plugging in with modules
      2. 6.1.2 Implementing the generic code
      3. 6.1.3 Using the generic abstraction
      4. 6.1.4 Supporting asynchronous requests
      5. 6.1.5 Exercise: refactoring the to-do server
    2. 6.2 Using GenServer
      1. 6.2.1 OTP behaviours
      2. 6.2.2 Plugging into GenServer
      3. 6.2.3 Handling requests
      4. 6.2.4 Handling plain messages
      5. 6.2.5 Other GenServer features
      6. 6.2.6 Process lifecycle
      7. 6.2.7 OTP-compliant processes
      8. 6.2.8 Exercise: GenServer-powered to-do server
    3. Summary
  18. Chapter 7: Building a concurrent system
    1. 7.1 Working with the mix project
    2. 7.2 Managing multiple to-do lists
      1. 7.2.1 Implementing a cache
      2. 7.2.2 Writing tests
      3. 7.2.3 Analyzing process dependencies
    3. 7.3 Persisting data
      1. 7.3.1 Encoding and persisting
      2. 7.3.2 Using the database
      3. 7.3.3 Analyzing the system
      4. 7.3.4 Addressing the process bottleneck
      5. 7.3.5 Exercise: pooling and synchronizing
    4. 7.4 Reasoning with processes
    5. Summary
  19. Chapter 8: Fault-tolerance basics
    1. 8.1 Runtime errors
      1. 8.1.1 Error types
      2. 8.1.2 Handling errors
    2. 8.2 Errors in concurrent systems
      1. 8.2.1 Linking processes
      2. 8.2.2 Monitors
    3. 8.3 Supervisors
      1. 8.3.1 Preparing the existing code
      2. 8.3.2 Starting the supervisor process
      3. 8.3.3 Child specification
      4. 8.3.4 Wrapping the supervisor
      5. 8.3.5 Using a callback module
      6. 8.3.6 Linking all processes
      7. 8.3.7 Restart frequency
    4. Summary
  20. Chapter 9: Isolating error effects
    1. 9.1 Supervision trees
      1. 9.1.1 Separating loosely dependent parts
      2. 9.1.2 Rich process discovery
      3. 9.1.3 Via tuples
      4. 9.1.4 Registering database workers
      5. 9.1.5 Supervising database workers
      6. 9.1.6 Organizing the supervision tree
    2. 9.2 Starting processes dynamically
      1. 9.2.1 Registering to-do servers
      2. 9.2.2 Dynamic supervision
      3. 9.2.3 Finding to-do servers
      4. 9.2.4 Using temporary restart strategy
      5. 9.2.5 Testing the system
    3. 9.3 “Let it crash”
      1. 9.3.1 Processes that shouldn’t crash
      2. 9.3.2 Handling expected errors
      3. 9.3.3 Preserving the state
    4. Summary
  21. Chapter 10: Beyond GenServer
    1. 10.1 Tasks
      1. 10.1.1 Awaited tasks
      2. 10.1.2 Non-awaited tasks
    2. 10.2 Agents
      1. 10.2.1 Basic use
      2. 10.2.2 Agents and concurrency
      3. 10.2.3 Agent-powered to-do server
      4. 10.2.4 Limitations of agents
    3. 10.3 ETS tables
      1. 10.3.1 Basic operations
      2. 10.3.2 ETS powered key/value store
      3. 10.3.3 Other ETS operations
      4. 10.3.4 Exercise: process registry
    4. Summary
  22. Chapter 11: Working with components
    1. 11.1 OTP applications
      1. 11.1.1 Creating applications with the mix tool
      2. 11.1.2 The application behavior
      3. 11.1.3 Starting the application
      4. 11.1.4 Library applications
      5. 11.1.5 Creating a to-do application
      6. 11.1.6 The application folder structure
    2. 11.2 Working with dependencies
      1. 11.2.1 Adding a dependency
      2. 11.2.2 Adapting the pool
      3. 11.2.3 Visualizing the system
    3. 11.3 Building a web server
      1. 11.3.1 Choosing dependencies
      2. 11.3.2 Starting the server
      3. 11.3.3 Handling requests
      4. 11.3.4 Reasoning about the system
    4. 11.4 Configuring applications
      1. 11.4.1 Application environment
      2. 11.4.2 Varying configuration
      3. 11.4.3 Config script considerations
    5. Summary
  23. Chapter 12: Building a distributed system
    1. 12.1 Distribution primitives
      1. 12.1.1 Starting a cluster
      2. 12.1.2 Communicating between nodes
      3. 12.1.3 Process discovery
      4. 12.1.4 Links and monitors
      5. 12.1.5 Other distribution services
    2. 12.2 Building a fault-tolerant cluster
      1. 12.2.1 Cluster design
      2. 12.2.2 The distributed to-do cache
      3. 12.2.3 Implementing a replicated database
      4. 12.2.4 Testing the system
      5. 12.2.5 Detecting partitions
      6. 12.2.6 Highly available systems
    3. 12.3 Network considerations
      1. 12.3.1 Node names
      2. 12.3.2 Cookies
      3. 12.3.3 Hidden nodes
      4. 12.3.4 Firewalls
    4. Summary
  24. Chapter 13: Running the system
    1. 13.1 Running a system with Elixir tools
      1. 13.1.1 Using the mix and elixir commands
      2. 13.1.2 Running scripts
      3. 13.1.3 Compiling for production
    2. 13.2 OTP releases
      1. 13.2.1 Building a release with distillery
      2. 13.2.2 Using a release
      3. 13.2.3 Release contents
    3. 13.3 Analyzing system behavior
      1. 13.3.1 Debugging
      2. 13.3.2 Logging
      3. 13.3.3 Interacting with the system
      4. 13.3.4 Tracing
    4. Summary
  25. Index
  26. List of Figures
  27. List of Tables
  28. List of Listings

Product Information

  • Title: Elixir in Action, Second Edition
  • Author(s): Sasa Juric
  • Release date: February 2019
  • Publisher(s): Manning Publications
  • ISBN: 9781617295027