Cloud Bigtable

gRPC · port 9094 · orchestrated
Orchestrated service. Bigtable runs as a Docker container managed by localgcp. Requires Docker. Container starts lazily on first connection.

Quick start

$ localgcp up --services=bigtable

Note: Bigtable listens on port 9094 instead of the standard 8086 (which is used by Secret Manager).

Go SDK example

Connect to the local Bigtable emulator, create a table, write a row, and read it back:

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    bigtable "cloud.google.com/go/bigtable"
)

func main() {
    // Point the SDK at localgcp
    os.Setenv("BIGTABLE_EMULATOR_HOST", "localhost:9094")

    ctx := context.Background()
    project := "my-project"
    instance := "my-instance"

    // Admin client -- create table and column family
    admin, err := bigtable.NewAdminClient(ctx, project, instance)
    if err != nil {
        log.Fatal(err)
    }
    defer admin.Close()

    if err := admin.CreateTable(ctx, "my-table"); err != nil {
        log.Fatal(err)
    }
    if err := admin.CreateColumnFamily(ctx, "my-table", "cf1"); err != nil {
        log.Fatal(err)
    }

    // Data client -- write and read
    client, err := bigtable.NewClient(ctx, project, instance)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    tbl := client.Open("my-table")

    // Write a row
    mut := bigtable.NewMutation()
    mut.Set("cf1", "greeting", bigtable.Now(), []byte("Hello, localgcp!"))
    if err := tbl.Apply(ctx, "row-1", mut); err != nil {
        log.Fatal(err)
    }

    // Read it back
    row, err := tbl.ReadRow(ctx, "row-1")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Row: %s\n", row["cf1"][0].Value)
}

Environment variable

The Go (and Java) Bigtable SDKs respect the BIGTABLE_EMULATOR_HOST variable. Set it before running your application:

$ export BIGTABLE_EMULATOR_HOST=localhost:9094

When this variable is set the SDK skips authentication and connects directly to the emulator.

How it works

localgcp runs a lazy TCP proxy on port 9094. The first time a client opens a connection, localgcp pulls the emulator image (if not cached) and starts a Docker container running gcloud beta emulators bigtable start. Subsequent connections reuse the running container. The proxy forwards gRPC traffic transparently -- your SDK cannot tell the difference from the real service.

Pre-fetching

To avoid the cold-start delay on first connection, pull the emulator image ahead of time:

$ docker pull google/cloud-sdk:emulators

Not yet supported