Book description
Explore software engineering methodologies, techniques, and best practices in Go programming to build easy-to-maintain software that can effortlessly scale on demand
Key Features
- Apply best practices to produce lean, testable, and maintainable Go code to avoid accumulating technical debt
- Explore Go's built-in support for concurrency and message passing to build high-performance applications
- Scale your Go programs across machines and manage their life cycle using Kubernetes
Book Description
Over the last few years, Go has become one of the favorite languages for building scalable and distributed systems. Its opinionated design and built-in concurrency features make it easy for engineers to author code that efficiently utilizes all available CPU cores.
This Golang book distills industry best practices for writing lean Go code that is easy to test and maintain, and helps you to explore its practical implementation by creating a multi-tier application called Links 'R' Us from scratch. You'll be guided through all the steps involved in designing, implementing, testing, deploying, and scaling an application. Starting with a monolithic architecture, you'll iteratively transform the project into a service-oriented architecture (SOA) that supports the efficient out-of-core processing of large link graphs. You'll learn about various cutting-edge and advanced software engineering techniques such as building extensible data processing pipelines, designing APIs using gRPC, and running distributed graph processing algorithms at scale. Finally, you'll learn how to compile and package your Go services using Docker and automate their deployment to a Kubernetes cluster.
By the end of this book, you'll know how to think like a professional software developer or engineer and write lean and efficient Go code.
What you will learn
- Understand different stages of the software development life cycle and the role of a software engineer
- Create APIs using gRPC and leverage the middleware offered by the gRPC ecosystem
- Discover various approaches to managing package dependencies for your projects
- Build an end-to-end project from scratch and explore different strategies for scaling it
- Develop a graph processing system and extend it to run in a distributed manner
- Deploy Go services on Kubernetes and monitor their health using Prometheus
Who this book is for
This Golang programming book is for developers and software engineers looking to use Go to design and build scalable distributed systems effectively. Knowledge of Go programming and basic networking principles is required.
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Contributors
- Preface
- Section 1: Software Engineering and the Software Development Life Cycle
- A Bird's-Eye View of Software Engineering
- Section 2: Best Practices for Maintainable and Testable Go Code
-
Best Practices for Writing Clean and Maintainable Go Code
- The SOLID principles of object-oriented design
- Organizing code into packages
- Tips and tools for writing lean and easy-to-maintain Go code
- Summary
- Questions
- Further reading
- Dependency Management
-
The Art of Testing
- Technical requirements
- Unit testing
- Integration versus functional testing
- Smoke tests
- Chaos testing – breaking your systems in fun and interesting ways!
- Tips and tricks for writing tests
- Summary
- Questions
- Further reading
- Section 3: Designing and Building a Multi-Tier System from Scratch
- The Links 'R'; Us Project
-
Building a Persistence Layer
- Technical requirements
- Exploring a taxonomy of database systems
- Understanding the need for a data layer abstraction
-
Designing the data layer for the link graph component
- Creating an ER diagram for the link graph store
- Listing the required set of operations for the data access layer
- Defining a Go interface for the link graph
- Verifying graph implementations using a shared test suite
- Implementing an in-memory graph store
- Scaling across with a CockroachDB-backed graph implementation
- Designing the data layer for the text indexer component
- Summary
- Questions
- Further reading
-
Data-Processing Pipelines
- Technical requirements
-
Building a generic data-processing pipeline in Go
- Design goals for the pipeline package
- Modeling pipeline payloads
- Multistage processing
- Strategies for handling errors
- Synchronous versus asynchronous pipelines
- Implementing a stage worker for executing payload processors
- Implementing the input source worker
- Implementing the output sink worker
- Putting it all together – the pipeline API
-
Building a crawler pipeline for the Links 'R' Us project
- Defining the payload for the crawler
- Implementing a source and a sink for the crawler
- Fetching the contents of graph links 
- Extracting outgoing links from retrieved webpages
- Extracting the title and text from retrieved web pages
- Inserting discovered outgoing links to the graph
- Indexing the contents of retrieved web pages
- Assembling and running the pipeline
- Summary
- Questions
- Further reading
-
Graph-Based Data Processing
- Technical requirements
- Exploring the Bulk Synchronous Parallel model
- Building a graph processing system in Go
-
Solving interesting graph problems
- Searching graphs for the shortest path
- Graph coloring
-
Calculating PageRank scores
- The model of the random surfer
- An iterative approach to PageRank score calculation
- Reaching convergence – when should we stop iterating?
- Web graphs in the real world – dealing with dead ends
- Defining an API for the PageRank calculator
- Implementing a compute function to calculate PageRank scores
- Summary
- Further reading
-
Communicating with the Outside World
- Technical requirements
- Designing robust, secure, and backward-compatible REST APIs
- Building RPC-based APIs with the help of gRPC
- Decoupling Links 'R' Us components from the underlying data stores
- Summary
- Questions
- Further reading
-
Building, Packaging, and Deploying Software
- Technical requirements
- Building and packaging Go services using Docker
- A gentle introduction to Kubernetes
-
Building and deploying a monolithic version of Links 'R' Us
- Distributing computation across application instances
- Building wrappers for the application services
- The crawler service
- The PageRank calculator service
- Serving a fully functioning frontend to users
- Orchestrating the execution of individual services
- Putting everything together
- Deploying and scaling the monolith on Kubernetes
- Summary
- Questions
- Further reading
- Section 4: Scaling Out to Handle a Growing Number of Users
-
Splitting Monoliths into Microservices
- Technical requirements
- Monoliths versus service-oriented architectures
- Monitoring the state of your microservices
- Building a microservice-based version of Links 'R' Us
- Summary
- Questions
- Further reading
-
Building Distributed Graph-Processing Systems
- Technical requirements
- Introducing the master/worker model
-
Out-of-core distributed graph processing
- Describing the system architecture, requirements, and limitations
- Modeling a state machine for executing graph computations
- Establishing a communication protocol between workers and masters
- Defining abstractions for working with bi-directional gRPC streams
- Creating a distributed barrier for the graph execution steps
- Creating custom executor factories for wrapping existing graph instances
- Coordinating the execution of a graph job
- Defining package-level APIs for working with master and worker nodes
- Deploying a distributed version of the Links 'R' Us PageRank calculator
- Summary
- Questions
- Further reading
-
Metrics Collection and Visualization
- Technical requirements
- Monitoring from the perspective of a site reliability engineer
- Exploring options for collecting and aggregating metrics
- Visualizing collected metrics using Grafana
- Using Prometheus as an end-to-end solution for alerting
- Summary
- Questions
- Further reading
- Epilogue
- Assessments
- Other Books You May Enjoy
Product information
- Title: Hands-On Software Engineering with Golang
- Author(s):
- Release date: January 2020
- Publisher(s): Packt Publishing
- ISBN: 9781838554491
You might also like
book
Hands-On Software Architecture with Golang
Understand the principles of software architecture with coverage on SOA, distributed and messaging systems, and database …
book
Event-Driven Architecture in Golang
Begin building event-driven microservices, including patterns to handle data consistency and resiliency Key Features Explore the …
video
Up and Running with Concurrency in Go (Golang)
According to the most recent developer surveys, Go(lang) is one of the world’s most desired and …
book
Domain-Driven Design with Golang
Understand the concept of Domain-driven design and build two DDD systems from scratch that can be …