Cloud Native Go

Book description

What do Docker, Kubernetes, and Prometheus have in common? All of these cloud native technologies are written in the Go programming language. This practical book shows you how to use Go's strengths to develop cloud native services that are scalable and resilient, even in an unpredictable environment. You'll explore the composition and construction of these applications, from lower-level features of Go to mid-level design patterns to high-level architectural considerations.

Each chapter builds on the lessons of the last, walking intermediate to advanced developers through Go to construct a simple but fully featured distributed key-value store. You'll learn best practices for adopting Go as your development language for solving cloud native management and deployment issues.

  • Learn how cloud native applications differ from other software architectures
  • Understand how Go can solve the challenges of designing scalable distributed services
  • Leverage Go's lower-level features, such as channels and goroutines, to implement a reliable cloud native service
  • Explore what "service reliability" is and what it has to do with cloud native
  • Apply a variety of patterns, abstractions, and tooling to build and manage complex distributed systems

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. O’Reilly Online Learning
    6. How to Contact Us
    7. Acknowledgments
  2. I. Going Cloud Native
  3. 1. What Is a “Cloud Native” Application?
    1. The Story So Far
    2. What Is Cloud Native?
      1. Scalability
      2. Loose Coupling
      3. Resilience
      4. Manageability
      5. Observability
    3. Why Is Cloud Native a Thing?
    4. Summary
  4. 2. Why Go Rules the Cloud Native World
    1. The Motivation Behind Go
    2. Features for a Cloud Native World
      1. Composition and Structural Typing
      2. Comprehensibility
      3. CSP-Style Concurrency
      4. Fast Builds
      5. Linguistic Stability
      6. Memory Safety
      7. Performance
      8. Static Linking
      9. Static Typing
    3. Summary
  5. II. Cloud Native Go Constructs
  6. 3. Go Language Foundations
    1. Basic Data Types
      1. Booleans
      2. Simple Numbers
      3. Complex Numbers
      4. Strings
    2. Variables
      1. Short Variable Declarations
      2. Zero Values
      3. The Blank Identifier
      4. Constants
    3. Container Types: Arrays, Slices, and Maps
      1. Arrays
      2. Slices
      3. Maps
    4. Pointers
    5. Control Structures
      1. Fun with for
      2. The if Statement
      3. The switch Statement
    6. Error Handling
      1. Creating an Error
    7. Putting the Fun in Functions: Variadics and Closures
      1. Functions
      2. Variadic Functions
      3. Anonymous Functions and Closures
    8. Structs, Methods, and Interfaces
      1. Structs
      2. Methods
      3. Interfaces
      4. Composition with Type Embedding
    9. The Good Stuff: Concurrency
      1. Goroutines
      2. Channels
      3. Select
    10. Summary
  7. 4. Cloud Native Patterns
    1. The Context Package
      1. What Context Can Do for You
      2. Creating Context
      3. Defining Context Deadlines and Timeouts
      4. Defining Request-Scoped Values
      5. Using a Context
    2. Layout of this Chapter
    3. Stability Patterns
      1. Circuit Breaker
      2. Debounce
      3. Retry
      4. Throttle
      5. Timeout
    4. Concurrency Patterns
      1. Fan-In
      2. Fan-Out
      3. Future
      4. Sharding
    5. Summary
  8. 5. Building a Cloud Native Service
    1. Let’s Build a Service!
      1. What’s a Key-Value Store?
    2. Requirements
      1. What Is Idempotence and Why Does It Matter?
      2. The Eventual Goal
    3. Generation 0: The Core Functionality
      1. Your Super Simple API
    4. Generation 1: The Monolith
      1. Building an HTTP Server with net/http
      2. Building an HTTP Server with gorilla/mux
      3. Building a RESTful Service
      4. Making Your Data Structure Concurrency-Safe
    5. Generation 2: Persisting Resource State
      1. What’s a Transaction Log?
      2. Storing State in a Transaction Log File
      3. Storing State in an External Database
    6. Generation 3: Implementing Transport Layer Security
      1. Transport Layer Security
      2. Private Key and Certificate Files
      3. Securing Your Web Service with HTTPS
      4. Transport Layer Summary
    7. Containerizing Your Key-Value Store
      1. Docker (Absolute) Basics
      2. Building Your Key-Value Store Container
      3. Externalizing Container Data
    8. Summary
  9. III. The Cloud Native Attributes
  10. 6. It’s All About Dependability
    1. What’s the Point of Cloud Native?
    2. It’s All About Dependability
    3. What Is Dependability and Why Is It So Important?
      1. Dependability: It’s Not Just for Ops Anymore
    4. Achieving Dependability
      1. Fault Prevention
      2. Fault Tolerance
      3. Fault Removal
      4. Fault Forecasting
    5. The Continuing Relevance of the Twelve-Factor App
      1. I. Codebase
      2. II. Dependencies
      3. III. Configuration
      4. IV. Backing Services
      5. V. Build, Release, Run
      6. VI. Processes
      7. VII. Data Isolation
      8. VIII. Scalability
      9. IX. Disposability
      10. X. Development/Production Parity
      11. XI. Logs
      12. XII. Administrative Processes
    6. Summary
  11. 7. Scalability
    1. What Is Scalability?
      1. Different Forms of Scaling
    2. The Four Common Bottlenecks
    3. State and Statelessness
      1. Application State Versus Resource State
      2. Advantages of Statelessness
    4. Scaling Postponed: Efficiency
      1. Efficient Caching Using an LRU Cache
      2. Efficient Synchronization
      3. Memory Leaks Can…fatal error: runtime: out of memory
      4. On Efficiency
    5. Service Architectures
      1. The Monolith System Architecture
      2. The Microservices System Architecture
      3. Serverless Architectures
    6. Summary
  12. 8. Loose Coupling
    1. Tight Coupling
      1. Tight Coupling Takes Many Forms
    2. Communications Between Services
    3. Request-Response Messaging
      1. Common Request-Response Implementations
      2. Issuing HTTP Requests with net/http
      3. Remote Procedure Calls with gRPC
    4. Loose Coupling Local Resources with Plug-ins
      1. In-Process Plug-ins with the plugin Package
      2. HashiCorp’s Go Plug-in System over RPC
    5. Hexagonal Architecture
      1. The Architecture
      2. Implementing a Hexagonal Service
    6. Summary
  13. 9. Resilience
    1. Keeping on Ticking: Why Resilience Matters
    2. What Does It Mean for a System to Fail?
      1. Building for Resilience
    3. Cascading Failures
      1. Preventing Overload
    4. Play It Again: Retrying Requests
      1. Backoff Algorithms
      2. Circuit Breaking
      3. Timeouts
      4. Idempotence
    5. Service Redundancy
      1. Designing for Redundancy
      2. Autoscaling
    6. Healthy Health Checks
      1. What Does It Mean for an Instance to Be “Healthy”?
      2. The Three Types of Health Checks
      3. Failing Open
    7. Summary
  14. 10. Manageability
    1. What Is Manageability and Why Should I Care?
    2. Configuring Your Application
      1. Configuration Good Practice
      2. Configuring with Environment Variables
      3. Configuring with Command-Line Arguments
      4. Configuring with Files
      5. Viper: The Swiss Army Knife of Configuration Packages
    3. Feature Management with Feature Flags
      1. The Evolution of a Feature Flag
      2. Generation 0: The Initial Implementation
      3. Generation 1: The Hard-Coded Feature Flag
      4. Generation 2: The Configurable Flag
      5. Generation 3: Dynamic Feature Flags
    4. Summary
  15. 11. Observability
    1. What Is Observability?
      1. Why Do We Need Observability?
      2. How Is Observability Different from “Traditional” Monitoring?
    2. The “Three Pillars of Observability”
    3. OpenTelemetry
      1. The OpenTelemetry Components
    4. Tracing
      1. Tracing Concepts
      2. Tracing with OpenTelemetry
      3. Putting It All Together: Tracing
    5. Metrics
      1. Push Versus Pull Metric Collection
      2. Metrics with OpenTelemetry
      3. Putting It All Together: Metrics
    6. Logging
      1. Better Logging Practices
      2. Logging with Go’s Standard log Package
      3. The Zap Logging Package
    7. Summary
  16. Index
  17. About the Author

Product information

  • Title: Cloud Native Go
  • Author(s): Matthew A. Titmus
  • Release date: April 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492076339