Skip to main content

Building and Deploying a Blockchain Indexer on Google Cloud

Updated 8 min readMarkdown
Building and Deploying a Blockchain Indexer on Google Cloud

For my first cloud engineering portfolio project, I built and deployed a production-style Stablecoin Whale Monitor on Google Cloud.

The application indexes large USDC and USDT transfers on Ethereum, stores the events in Cloud Storage, exposes them through an API, and displays them in a public dashboard at swm.josephdara.com.

What began as a blockchain indexing script eventually became a broader cloud engineering project involving private networking, IAM, load balancing, TLS, CDN caching, edge security, Linux service management, and post-deployment debugging.

What the application does

The indexer monitors Ethereum mainnet for ERC-20 Transfer events emitted by the official USDC and USDT contracts.

It uses Google Blockchain JSON-RPC to retrieve logs, decodes each qualifying transfer, and records information such as:

  • Token and contract address

  • Sender and receiver

  • Transaction hash

  • Block number and timestamp

  • Raw and formatted amount

  • Transfer type: normal, mint, or burn

Only transfers above the configured whale threshold are stored.

Google limits eth_getLogs requests to five blocks, so the production configuration uses:

BLOCK_BATCH_SIZE=5
CONFIRMATION_BUFFER=6

The confirmation buffer reduces the risk of publishing events from short blockchain reorganizations, although it does not guarantee permanent finality.

Checkpointing and replay safety

The indexer maintains a checkpoint containing the last successfully processed block and its block hash.

After a restart, it resumes from that checkpoint rather than beginning again. It also verifies that the checkpointed block hash still matches Ethereum’s canonical chain. A mismatch stops the indexer and reports a possible deep reorganization.

Each event receives a deterministic Cloud Storage object name:

ethereum/YYYY/MM/DD/<block>-<logIndex>-<transactionHash>.json

Objects are created with ifGenerationMatch=0, meaning an event can only be written if it does not already exist. If a replay encounters an existing object, Cloud Storage returns 412 Precondition Failed, which the indexer treats as successful duplicate suppression.

This makes the indexing process safe to restart and replay.

Why I used Cloud Storage instead of a database

Cloud Storage is the canonical datastore for the project. I intentionally avoided Cloud SQL and Firestore to keep the architecture simple and object-oriented.

Two private buckets are used:

Events bucket
└── Immutable transaction-event objects

State bucket
├── checkpoint.json
└── token-metadata.json

The separation made it easier to apply least-privilege IAM.

The indexer can create event objects but cannot overwrite or delete event history. It has additional permissions on the state bucket because checkpoints must be replaced.

The web service account is read-only and cannot modify either bucket.

No downloadable service-account keys are used. Each VM receives its identity directly through its attached service account.

API and frontend

The backend is an Express API that rebuilds an in-memory query index from Cloud Storage.

It exposes:

GET /api/transfers
GET /api/transfers/:txHash
GET /api/health
GET /api/stats

The transfers endpoint supports:

  • Newest-first ordering

  • Cursor pagination

  • USDC and USDT filtering

  • Minimum-amount filtering

  • Sender or receiver address filtering

Transaction lookup returns every qualifying Transfer log emitted by a transaction rather than assuming one transaction equals one transfer.

The frontend uses Next.js, React, and TypeScript. It is exported as a static site and served by Nginx.

It displays 50 transfers per page and includes filtering, transaction search, Etherscan links, health information, and automatic refresh.

Google Cloud architecture

The application runs in a custom VPC in Toronto:

Region: northamerica-northeast2
Zone: northamerica-northeast2-b

The VPC contains two subnets:

web-subnet      10.10.1.0/24
indexer-subnet  10.10.2.0/24

The web VM runs Nginx, the Express API, and the static frontend.

The indexer VM is private and has no external IP address. It reaches the Ethereum RPC endpoint through Cloud NAT and accesses Google services through Private Google Access.

Administrative SSH is restricted to approved public IP addresses. The web VM also acts as a jump host for the private indexer.

Administrator
  → Web VM
  → Private indexer VM

Express listens only on:

127.0.0.1:3001

It is never publicly accessible.

Public traffic flow

The public application is served through a global external Application Load Balancer:

Browser
  → HTTPS load balancer
  → Certificate Manager
  → Cloud Armor
  → URL map
      ├── /api and /api/* → API backend
      └── everything else → Static backend with CDN
  → Nginx

TLS terminates at the load balancer using a Google-managed certificate.

HTTP requests are redirected to HTTPS at the load balancer. The load balancer then connects to Nginx over port 80.

The web VM’s port 80 is not publicly open. Its firewall accepts traffic only from Google’s load-balancer and health-check ranges. This prevents users from connecting directly to the VM and bypassing Cloud Armor.

Cloud CDN is enabled only for the static frontend backend. API responses use a separate backend service with CDN disabled.

Cloud Armor provides edge protection and API rate limiting.

Deployment

I excluded local secrets, dependencies, build output, and test data:

.env
frontend/.env.local
node_modules/
frontend/node_modules/
frontend/.next/
frontend/out/
data/
tmp/

Dependencies were installed directly on Linux:

pnpm install --frozen-lockfile --prod

The frontend was rebuilt on the web VM:

cd /swm/frontend
pnpm install --frozen-lockfile
env -u NEXT_PUBLIC_API_BASE_URL pnpm build

Leaving NEXT_PUBLIC_API_BASE_URL unset causes the frontend to call the API through the same Nginx and load-balancer origin.

The API and indexer run as dedicated Linux users under systemd:

swm-api
swm-indexer

Environment files are stored under /etc/swm with mode 600. The RPC credential exists only on the indexer VM.

Nginx serves the static frontend and proxies API requests internally:

/api/* → 127.0.0.1:3001

Debugging a production memory failure

The most important learning experience came after deployment.

The frontend periodically displayed:

Data could not be loaded.
Could not load transfer data (503)

The load balancer returned:

no healthy upstream

Nginx returned 502 Bad Gateway, indicating that Express was unavailable.

I inspected the systemd journal:

sudo journalctl -u swm-api --since "30 minutes ago"

The logs revealed:

FATAL ERROR: Ineffective mark-compacts near heap limit
Allocation failed - JavaScript heap out of memory

The API was exhausting approximately 1 GB of JavaScript heap, crashing, and being restarted by systemd.

Root cause

The API originally refreshed its index every 30 seconds using setInterval.

Each refresh:

  1. Listed every event object in Cloud Storage.

  2. Downloaded every JSON object.

  3. Built another complete in-memory array.

A full refresh took around six minutes, but a new refresh started every 30 seconds. This allowed many complete scans to overlap, eventually exhausting the Node.js heap.

The load balancer was not the root problem. It was correctly marking the backend unhealthy while Express was down.

The fix

I refactored the Cloud Storage adapter to use an asynchronous iterator.

The new implementation:

  • Lists objects in pages of 1,000

  • Processes pages sequentially

  • Downloads events one at a time

  • Tracks previously indexed object names

  • Downloads only newly created immutable events

  • Prevents concurrent refreshes

  • Schedules the next refresh only after the previous one finishes

The API still keeps one in-memory index for fast filtering, pagination, and transaction lookup, but it no longer creates multiple overlapping copies.

I added automated tests for:

  • Paginated GCS iteration

  • Skipping known objects

  • Incremental event discovery

  • Concurrent refresh coalescing

The final test suite contains 17 passing tests.

Monitoring and operational work

Following the production incident, I designed monitoring for:

  • Public API availability

  • VM memory utilization

  • Node.js heap failures

  • systemd service crashes

The monitoring design uses Cloud Monitoring, Cloud Logging, an external HTTPS uptime check, and the Ops Agent.

The key alert conditions are:

/api/health unavailable
VM memory above 80% for five minutes
JavaScript heap out of memory
swm-api.service process failure

This provides both proactive warning and post-failure notification.

Technologies used

Application

  • Node.js

  • Express

  • Next.js

  • React

  • TypeScript

  • pnpm

  • Nginx

  • systemd

Blockchain

  • Ethereum

  • ERC-20 Transfer events

  • USDC

  • USDT

  • Google Blockchain JSON-RPC

Google Cloud

  • Custom VPC

  • Compute Engine

  • Cloud Router

  • Cloud NAT

  • Private Google Access

  • Cloud Storage

  • IAM and service accounts

  • Global external Application Load Balancer

  • Certificate Manager

  • Cloud Armor

  • Cloud CDN

  • Cloud Monitoring and Logging

What I learned

This project gave me experience across the full lifecycle of a cloud application:

  • Designing private and public network boundaries

  • Applying least-privilege IAM

  • Building replay-safe blockchain ingestion

  • Managing immutable and mutable object storage

  • Deploying Linux services with systemd

  • Configuring Nginx and HTTPS load balancing

  • Separating cacheable frontend traffic from dynamic API traffic

  • Diagnosing failures across the browser, load balancer, Nginx, systemd, Node.js, and Cloud Storage

  • Refactoring a working local design after discovering production-scale behavior

The biggest lesson was that deployment success is not the end of the engineering process. The application worked locally and passed its tests, but production data volume exposed a concurrency and memory problem that was not visible during development.

Finding and fixing that issue turned the project from a basic cloud deployment into a much more valuable reliability-engineering exercise.

No comments yet. Be the first to comment.