Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Matthew A. Titmus

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

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Cloud Native Go: Building Reliable Services in Unreliable Environments ## 【One-Line Pitch】 A practical, project-driven guide that teaches intermediate to advanced developers how to leverage Go's unique strengths—goroutines, channels, and its minimalist design—to build scalable, resilient cloud native services, culminating in a fully functional distributed key-value store. ## 【Book Arc】 - **Opening (~0%–9%)**: Defines what "cloud native" actually means—contrasting it with traditional monolithic architectures—and explains why Go was purpose-built for this era. Covers the historical frustrations with existing languages (poor readability, slow builds, inefficiency) that motivated Go's design philosophy of simplicity and comprehensibility. - **Early (~9%–16%)**: Dives into Go's language foundations, including its notable non-features (no inheritance, no exceptions) and structural typing approach. Includes benchmark comparisons showing Go's performance sits comfortably between manual-memory-management languages (C++, Rust) and interpreted languages (Python, Ruby), making it ideal for network services. - **Early (~16%–25%)**: Covers core language mechanics—basic data types, slices, control structures, defer statements, and pointers. This section builds the syntactic and semantic foundation needed before tackling concurrency, with emphasis on idiomatic Go patterns like using `for` as a `while` loop and proper resource cleanup with `defer`. - **Early (~25%–34%)**: Introduces Go's concurrency model—goroutines, channels, buffered channels, and the `select` statement for multiplexing channel operations. Also covers the `context` package for request-scoped cancellation and timeout propagation, including the controversial `WithValue` function and its caveats. - **Middle (~34%–47%)**: Presents cloud native design patterns—timeout, circuit breaker, and concurrency patterns like Split and Future. These patterns address the Fallacies of Distributed Computing, particularly the unreliability of networks. Transitions into building the key-value store service, starting with a minimal REST API using `net/http` and the Gorilla router. - **Middle (~47%–end)**: Continues the key-value store implementation, showing how to wire up HTTP handlers, test the service with `curl`, and evolve from a simple monolith toward a more distributed architecture. Each chapter builds on the previous, demonstrating how Go's features solve real distributed systems problems. ## 【Key Takeaways】 - **Cloud native is about embracing unreliability** (Opening): The core mindset shift is accepting that networks fail, services degrade, and systems must be designed for partial failure rather than assuming perfect infrastructure. This frames all subsequent design decisions. - **Go was designed for the cloud native era** (Early): Go's creators deliberately omitted features (inheritance, exceptions) and prioritized comprehensibility, fast builds, and efficiency. The result is a language where "less is more"—fewer features means fewer ways to write unclear code. - **Performance benchmarks show Go's sweet spot** (Early): Compiled, garbage-collected languages like Go perform comparably to manual-memory-management languages for most workloads, while being dramatically faster than interpreted languages. This makes Go practical for production services without the complexity of manual memory management. - **Slices and `defer` are foundational idioms** (Early): Slices provide flexible, array-backed views that are central to Go programming, while `defer` ensures resource cleanup in LIFO order—critical for writing correct, leak-free services. - **Channels and `select` enable composable concurrency** (Early): Buffered channels, ranging over channels, and `select` statements provide building blocks for complex concurrent patterns. The ability to multiplex multiple channels with `select` is particularly powerful for service orchestration. - **`context` is the standard for cancellation and timeouts** (Early): The `context` package provides a uniform mechanism for propagating cancellation signals and deadlines through call chains. However, `WithValue` for request-scoped values is controversial and should be used sparingly—the book itself avoids it. - **Cloud native patterns solve distributed systems problems** (Middle): Timeout, circuit breaker, and concurrency patterns like Split and Future directly address the Fallacies of Distributed Computing. These patterns are simple in concept but critical for preventing cascading failures. - **Go's standard library covers 80% of web service needs** (Middle): The `net/http` package, while less feature-rich than frameworks like Django, is adequate for most use cases and designed to be extensible. REST is the pragmatic choice for services with simple data needs. ## 【Reading Tips】 - **Skim the language foundations if you're already comfortable with Go** (Early, ~16%–25%): The chapters on basic types, control structures, and pointers are solid but standard. Focus instead on the concurrency and context sections, which contain the more distinctive material. - **Deep-read the cloud native patterns chapter** (Middle, ~34%–47%): This is where the book earns its title. The patterns—timeout, circuit breaker, Split, Future—are directly applicable to real distributed systems and are the most valuable content for practicing engineers. - **Follow along with the key-value store project** (Middle, ~47%–end): The book builds a working service incrementally. Code along rather than just reading—you'll internalize the patterns better and have a reference implementation to adapt. - **Pay attention to the "why" behind Go's design choices** (Opening, ~0%–9%): The early chapters explain not just what Go does but why it was designed this way. This context helps you make better idiomatic choices in your own code. - **Don't skip the benchmark analysis** (Early, ~9%–16%): The performance comparison across languages provides useful context for justifying Go adoption to stakeholders and understanding its trade-offs versus alternatives like Rust or Java. ## 【Coverage Limits】 This guide covers the book's progression from cloud native fundamentals through Go language basics, concurrency, design patterns, and initial service implementation. The excerpts do not cover the later chapters on advanced distributed systems topics, deployment, or operational concerns—readers should expect additional material beyond the key-value store's basic REST API. ##
Excerpt 1
to be updated each time NGINX or httpd had a new version!8 It could be said that “loose coupling” is just a restatement of the whole point of microservice ar...
View in text
Excerpt 2
ample has no init or post statements, only a bare condition. This is actually a big deal, because it means that for is able to fill the role traditionally oc...
View in text
Excerpt 3
dctx, cancel := context.WithTimeout(ctx, time.Second * 10) // Release resources if SlowOperation completes before timeout defer cancel() res, err := SlowOper...
View in text
Excerpt 4
", nil)) } 112 | Chapter 5: Building a Cloud Native Service err = Put(key, string(value)) // Store the value as a string if err != nil { // If we have an err...
View in text
Excerpt 5
} } Generation 2: Persisting Resource State | 141 As you can see, ListenAndServeTLS looks and feels almost exactly like ListenAnd Serve except that it has tw...
View in text
Excerpt 6
of functions as a service (FaaS) and event-driven architec‐ tures means this is no longer necessarily always the case. So, instead of the original text, I’ve...
View in text
Excerpt 7
te hard. It’s often difficult or impossible to simulate the serverless environment, and mocks are approximations at best. Cost Although the “pay-as-you-go” m...
View in text
Excerpt 8
uction to this section, the requirements for Go plug-in are really, really minimal: it just has to be a main package that exports one or more vari‐ ables or...
View in text
Tags
AI categories
Cloud NativeGoBackend
ISBN: 1492076333
Publisher: O'Reilly Media
Publish Year: 2021
Language: English
Pages: 436
File Format: PDF
File Size: 8.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…