Cloud Native Go: Building Reliable Services in Unreliable Environments

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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

Author(s): Matthew A. Titmus
Edition: 1
Publisher: O'Reilly Media
Year: 2021

Language: English
Commentary: Vector PDF
Pages: 436
City: Sebastopol, CA
Tags: Cloud Computing; Programming; Concurrency; Distributed Systems; Scalability; Docker; Design Patterns; Go; Kubernetes; Prometheus; Resilience; Observability; Manageability

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