1. Explain a 3-tier web app with a database on Google Cloud


    A 3-tier web application architecture separates its functions into three parts: a client-side user interface, a business logic tier (also known as the application tier or logic tier), and a data tier.

    1. User Interface (Presentation Tier): This is the top-most level of the application. The users interact with the application at this level. The user interface can be created using front-end technologies such as HTML, CSS, and JavaScript.

    2. Business Logic Tier (Application Tier): This middle part of the application processes the business logic of the application. It takes data input from the user interface, processes it, and sends it to the data tier. This can be created using server-side technologies such as Node.js, Python, or Java.

    3. Data Tier: The bottom level is the database that stores the data of the application. Data is stored, retrieved, and updated in this tier. Google Cloud SQL is a database service quite suitable for this tier.

    Your Google Cloud three-tier architecture can include:

    • A static website hosted on Google Cloud Storage (front-end tier)
    • A web application hosted on Google App Engine (application tier)
    • A database hosted on Google Cloud SQL (data tier)

    Here's an example TypeScript program that sets up a basic 3-tier architecture.

    import * as gcp from "@pulumi/gcp"; import * as pulumi from "@pulumi/pulumi"; // Create a cloud storage bucket for the static website const bucket = new gcp.storage.Bucket("website-bucket", { location: "US", website: { mainPageSuffix: "index.html", notFoundPage: "404.html", }, }); // Set the default object access control to public read const defaultObjectAccessControl = new gcp.storage.DefaultObjectAccessControl("public-read", { bucket: bucket.name, roleEntity: "READER:allUsers", }); // Set the bucket policy so that all objects uploaded are publicly readable new gcp.storage.BucketIAMBinding("bucketPublicRead", { bucket: bucket.name, role: "roles/storage.objectViewer", members: ["allUsers"], }); // App Engine instance to handle the application logic const app = new gcp.appengine.Application("app", { locationId: "us-central", project: gcp.config.project, }); // Cloud SQL Database instance for data storage const master = new gcp.sql.DatabaseInstance("master", { databaseVersion: "POSTGRES_9_6", settings: { tier: "db-f1-micro", }, }); export const bucketName = bucket.url; export const appURL = pulumi.interpolate`https://${app.defaultHostname}`; export const sqlConnName = master.connectionName;
    • bucket-website is a Google Cloud Storage bucket that will host static website files (Presentation Tier).
    • App Engine is set up with appengine.Application to handle computations (Application Tier).
    • sql.DatabaseInstance is used to create a Google Cloud SQL PostgreSQL database instance for data storage (Data Tier).