{"id":42482625,"url":"https://github.com/cloudspannerecosystem/spanner-gaming-sample","last_synced_at":"2026-01-28T11:15:47.300Z","repository":{"id":103682106,"uuid":"533361795","full_name":"cloudspannerecosystem/spanner-gaming-sample","owner":"cloudspannerecosystem","description":"This repository sets up a sample microservice architecture to highlight how Cloud Spanner integrates with other cloud technologies.","archived":false,"fork":false,"pushed_at":"2024-04-19T12:31:03.000Z","size":738,"stargazers_count":17,"open_issues_count":43,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-19T13:44:34.431Z","etag":null,"topics":["cloud-spanner","golang","google-cloud","kubernetes","sample-app","terraform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudspannerecosystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-09-06T14:26:25.000Z","updated_at":"2024-04-19T13:44:39.445Z","dependencies_parsed_at":null,"dependency_job_id":"bf40ff74-9b1d-4861-b999-a1d2ed0ad6fc","html_url":"https://github.com/cloudspannerecosystem/spanner-gaming-sample","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/cloudspannerecosystem/spanner-gaming-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-gaming-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-gaming-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-gaming-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-gaming-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudspannerecosystem","download_url":"https://codeload.github.com/cloudspannerecosystem/spanner-gaming-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-gaming-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28844862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T10:53:21.605Z","status":"ssl_error","status_checked_at":"2026-01-28T10:53:20.789Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-spanner","golang","google-cloud","kubernetes","sample-app","terraform"],"created_at":"2026-01-28T11:15:46.501Z","updated_at":"2026-01-28T11:15:47.271Z","avatar_url":"https://github.com/cloudspannerecosystem.png","language":"Go","readme":"# Spanner Gaming Samples\n\nThis repository contains sample code for the following use-cases when using Cloud Spanner for the backend:\n\n- Player creation and retrieval\n- Basic game creation and matchmaking that tracks game statistics like games won and games played\n- Item and currency acquisition for players in active games\n- Ability to buy and sell items on a tradepost\n\n![gaming_backend_services.png](images/gaming_backend_services.png)\n\n## REST endpoints\n\nThese are the REST endpoints exposed by backend services\n\n### profile service\n![gaming_backend_profile_rest.png](images/gaming_backend_profile_rest.png)\n\n### matchmaking service\n![gaming_backend_matchmaking_rest.png](images/gaming_backend_matchmaking_rest.png)\n\n### item service\n![gaming_backend_item_rest.png](images/gaming_backend_item_rest.png)\n\n### tradepost service\n![gaming_backend_tradepost_rest.png](images/gaming_backend_tradepost_rest.png)\n\n## Spanner schema\n\nThe Cloud Spanner schema that supports the backend services looks like this.\n\n### Players and games\n![gaming_schema_players_and_games.png](images/gaming_schema_players_and_games.png)\n\n### Items and player ledger\n![gaming_schema_items.png](images/gaming_schema_items.png)\n\n\u003e **NOTE:** Players table is repeated to show relation\n\n### Trades and player items\n![gaming_schema_trades.png](images/gaming_schema_trades.png)\n\n\u003e **NOTE:** Players and player_items tables are repeated to show relations\n\n## How to use this demo\n\nThis demo is meant to show you a working application with load against a Cloud Spanner database. To use this, you must:\n- Set up the infrastructure using either the below options\n  - Terraform to get a complete Spanner, GKE Autopilot and Cloud Deploy setup in your project\n  - gcloud command line to get a minimal setup of Cloud Spanner. Services and workloads will run locally.\n- Deploy the services\n- Deploy the workload generators\n- Generate load and observe Cloud Spanner behavior.\n- Clean up based on whether you deployed with gcloud or Terraform.\n\n### Setup infrastructure\n\nFirst you will want to set a variable to make it easier to navigate this directory.\n\n```bash\nexport DEMO_HOME=$(pwd)\n```\n\nBefore you set up the infrastructure, it is important to enable the appropriate APIs using the gcloud command line.\n\nYou must [install and configure gcloud](https://cloud.google.com/sdk/docs/install-sdk).\n\nWhen that's complete, ensure your gcloud project is set correctly.\n\n```bash\ngcloud config set project \u003cPROJECT_ID\u003e\n```\n\n\u003e **NOTE:** You can find your PROJECT_ID in [Cloud Console](https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects).\n\nThen you can set up the Spanner infrastructure using either the gcloud command line or Terraform. Instructions for both are below.\n\n#### Gcloud command line\n\nTo create the Spanner instance and database using gcloud, issue the following commands:\n\n```bash\ngcloud spanner instances create sample-instance --config=regional-us-central1 --description=gaming-instance --processing-units=500\n\ngcloud spanner databases create --instance sample-instance sample-game\n```\n\n\u003e **NOTE:** The above command will create an instance using the us-central1 [regional configuration](https://cloud.google.com/spanner/docs/instance-configurations) with a compute capacity of 500 processing units. Be aware that creating an instance will start billing your account unless you are under Google Cloud's [free trial credits](https://cloud.google.com/free).\n\n#### Terraform\nA terraform file is provided that creates the appropriate resources for these samples.\n\nResources that are created:\n- Spanner instance and database based on user variables in main.tfvars\n- GKE cluster to run the services\n- Artifact Registry to store the images for the services and the workloads\n- Cloud Deploy pipeline to deploy the services and workloads to the GKE cluster\n\nTo set up the infrastructure, do the following:\n\n- Copy `infrastructure/terraform.tfvars.sample` to `infrastructure/terraform.tfvars`\n- Modify `infrastructure/terraform.tfvars` for PROJECT and instance configuration\n- `terraform apply` from within infrastructure directory\n\n```bash\ncd $DEMO_HOME/infrastructure\nterraform init\ncp terraform.tfvars.sample terraform.tfvars\nvi terraform.tfvars # modify variables\n\n# Authenticate to gcloud services so Terraform can make changes\ngcloud auth application-default login\n\nterraform apply\n```\n\n### Schema management\nSchema is managed by [Wrench](https://github.com/cloudspannerecosystem/wrench).\n\nThere are two methods to deploy the schema: Cloud Build and local.\n\n\u003e **NOTE:** The schema must be in place for the services to work. Do not skip this step!\n\n#### Cloud Build schema management\n\nTo use cloud build schema management, run the cloud build commands:\n\n```bash\ncd $DEMO_HOME/schema\ngcloud builds submit --config=cloudbuild.yaml\n```\n\n\u003e **NOTE:** You must have used the Terraform setup to ensure the cloud build IAM permissions are correct.\n\n#### Local schema management\nLocal schema management simply means you run the migrations from your local machine. The schema changes still get applied to the remote Cloud Spanner instance.\n\nFirst, install wrench.\n\nAfter installing wrench, migrate the schema by running the `./scripts/schema.sh` file (replace project/instance/database information with what was used in terraform file):\n\n```bash\nexport SPANNER_PROJECT_ID=YOUR_PROJECT_ID\nexport SPANNER_INSTANCE_ID=YOUR_INSTANCE_ID\nexport SPANNER_DATABASE_ID=YOUR_DATABASE_ID\n./scripts/schema.sh\n```\n\n### Deployment\nYou can deploy the services and workloads to the GKE cluster that was configured by Terraform, or you can deploy them locally.\n\nTo deploy locally, follow the [instructions here](./docs/local.md).\n\n#### Deploy services to GKE\n\n\u003e **NOTE:** Deployment to GKE requires the Terraform setup have been completed above.\n\nTo deploy the services to GKE, use `gcloud build` from the `backend_services` directory:\n\n```bash\ncd $DEMO_HOME/backend_services\ngcloud builds submit --config=cloudbuild.yaml\n```\n\n\u003e **NOTE:** If the `cloudbuild.yaml` file doesn't exist in this directory, make sure to run the Terraform setup step again.\n\nOnce the services are deployed you can deploy the workloads to GKE.\n\n#### Deploy workloads to GKE\n\nTo deploy the workloads to GKE, use `gcloud build` from the `workloads` directory:\n\n```bash\ncd $DEMO_HOME/workloads\ngcloud builds submit --config=cloudbuild.yaml\n```\n\n\u003e **NOTE:** If the `cloudbuild.yaml` file doesn't exist in this directory, make sure to run the Terraform setup step again.\n\nFor more information on running the workloads, follow [these instructions](./docs/workloads.md).\n\n\u003e **NOTE:** It will take some time time to complete the build.\n\n### Kubectl\nTo interact with the GKE cluster, ensure kubectl is installed.\n\nOnce that is done, authenticate to GKE with the following commands:\n\n```bash\nexport USE_GKE_GCLOUD_AUTH_PLUGIN=True\nexport GKE_CLUSTER=sample-game-gke # change this based on the terraform configuration\ngcloud container clusters get-credentials $GKE_CLUSTER --region us-central1\nkubectl get namespaces\n```\n\nIf there are no issues with the kubectl commands, kubectl is properly authenticated.\n\n## Cleaning up\n\n### GCloud command line\n\nIf the Spanner instance was created using the gcloud command line, it can be delete using gcloud:\n\n```bash\ngcloud spanner instances delete sample-instance\n```\n\n### Terraform\n\nIf the infrastructure was created using terraform, then from the `infrastructure` directory you can destroy the infrastructure.\n\n```bash\ncd $DEMO_HOME/infrastructure\nterraform destroy\n```\n\n### Clean up builds and tests\nThe Makefile provides a `make clean` command that removes the binaries and docker containers that were created as part of building and testing the services as described in the [local setup](./docs/local.md).\n\n```bash\nmake clean\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudspannerecosystem%2Fspanner-gaming-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudspannerecosystem%2Fspanner-gaming-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudspannerecosystem%2Fspanner-gaming-sample/lists"}