Mastering Serverless Applications with Google Cloud Run

Book Description

Learn how to build a serverless real-world application in the cloud that’s reliable, secure, maintainable, and can handle millions of users. If you have experience building traditional web applications, this practical guide shows you how to get started with serverless. Cloud engineer Wietse Venema takes you through the steps necessary to build serverless applications with Cloud Run, a container-based serverless platform on Google Cloud.

Through the course of the book, you’ll learn how to become productive with serverless technology. You will build and explore several example applications that highlight different parts of the serverless stack, using (light) frontend technology and Go on the back end. You can also follow the lessons in the book using your own project on Google Cloud Platform.

You’ll learn how to:

  • Build a serverless application with Google’s Cloud Run and Firestore
  • Approach testing and development
  • Handle user management and authentication
  • Combine serverless with a traditional relational database
  • Run and monitor production services
  • Integrate your application with external APIs

Publisher Resources

View/Submit Errata

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. O’Reilly Online Learning
    3. How to Contact Us
    4. Acknowledgments
  2. 1. The What and Why of Serverless
    1. Serverless Cloud Infrastructure
      1. Physical and Virtual Infrastructure
      2. Serverless Infrastructure
      3. Serverless Applications
    2. Key Benefits of Serverless
      1. Deployments are Easy
      2. There Are No Servers to Manage
      3. Scalable Out of the Box
      4. Resilience
      5. A Different Cost Model
    3. Concerns About Serverless
      1. Portability
      2. Unpredictable Costs
      3. When Things Go Really Wrong
      4. Migration Effort
      5. When You Don’t See the Benefits Work for You
      6. Is Serverless Only for Green-Field Projects?
    4. What about Kubernetes?
    5. Why Go
    6. Why Google Cloud
    7. Summary
    8. References
  3. 2. Understanding Cloud Run
    1. Getting Started with Google Cloud
    2. Services and Functions are Different
    3. First Service with Cloud Run
      1. Step 1: Write Code
      2. Step 2: Package It into a Container
      3. Step 3: Build with Cloud Build, Run with Cloud Run
    4. Understanding Cloud Run
      1. Elastic Scalability
      2. No Session Affinity
      3. Ephemeral Container Instances
      4. Down-Throttling Idle Instances
      5. Ephemeral Disk Storage
      6. Long-Lived TCP Connections
      7. Cloud Run Key Points
    5. Choosing a Serverless Compute Product on Google Cloud
      1. Source-based Functions with Cloud Functions
      2. Container-based Services with Cloud Run
      3. App Engine: Platform as a Service
      4. Key Differences
      5. What Will the Future Look Like?
    6. Summary
  4. 3. Building a Three-Tier App
    1. The Example App: a To-do List
      1. Managed mySQL, not Serverless
    2. Hands-On Learning: Stand Up Your Own To-do Application
      1. Create a Google Cloud Project
      2. Frontend: Static Files Served With NGINX
      3. A Package Manager and a Bundler
      4. The Frontend Container
      5. A Pipeline With Cloud Build: cloudbuild.yaml
      6. Allow Cloud Build to Deploy: IAM
    3. Setting up Cloud SQL
    4. Backend: Java-Based REST API with Micronaut
      1. Connecting to Cloud SQL
      2. Connecting Cloud SQL with a UNIX Domain Socket
      3. UNIX Domain Sockets Are Not Special
    5. Deploy the Backend to Cloud Run
    6. Effects of Longer Startup Times
    7. Introducing Jib: Wait, Where is The Dockerfile?
      1. Containers Can Be Hard
      2. Containers Are Great, But I Want a Containerless Experience
      3. Anatomy of a Container Image
      4. What Does Jib Do?
    8. How To Develop On Your Local Machine
      1. Working with Application Default Credentials
    9. SQL Database Performance
      1. Optimal Transaction Concurrency
      2. Resource Contention
      3. Limit Transaction Concurrency with Connection Pools
      4. Limit Transaction Concurrency with Maximum Instances
      5. When to Use Which?
      6. Bringing it All Together
      7. Finding the Right Values
      8. A Real World Example
    10. Running Cloud SQL in Production
      1. Settings to Enable
      2. Make Your Application Resilient Against Short Downtime
      3. Monitoring
    11. Cleaning Up
    12. Summary
  5. 4. Multiple Services Working Together
    1. Getting Started with the Example
      1. Create a Google Cloud Project
    2. Product Service
      1. Embedded Read-Only SQL Database
      2. Deploying the Service
    3. Frontend Service
    4. Private Cloud Run Services
      1. What is an Identity?
      2. How to Send Proof of Your Identity
      3. What Is an ID-Token?
      4. When is an ID-Token Valid For a Service?
      5. How Authorization Works: IAM Policy
      6. Getting an ID-Token
    5. Sending Authenticated Requests from the Command Line
      1. Making a Request with CURL
    6. Sending Authenticated Requests From a Local Service
      1. Exploring the Source Code
      2. Requesting the Service Account ID-Token
      3. Reusing the ID-Token for Next Requests
      4. Running the Frontend Service on Your Local Machine
    7. Resolving the URL of Another Cloud Run Service
      1. Rely on the Cloud Run URL Structure
      2. Configure Other Service URLs Using Environment Variables
      3. A Runtime Solution: Calling the Cloud Run API
    8. How to Deal with Tracing
    9. Is Service-to-Service Communication Secure?
      1. First Stop: Google Frontend Server
      2. From Google Frontend to Cloud Run Container
      3. What Happens When You Call Another Cloud Run Service
    10. What About Latency?
    11. Are Microservices Required?
      1. Big Service Limitations
      2. Multiple Services Limitations
      3. Good Reasons to Add a Separate Service
    12. Summary

Product Information

  • Title: Mastering Serverless Applications with Google Cloud Run
  • Author(s): Wietse Venema
  • Release date: September 2020
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492057093