Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
Your team is building a high-throughput financial application on Google Cloud that uses Spanner to store account balances and transfer logs. To meet latency and data integrity requirements, your implementation must:
INSERT and UPDATE statements atomically within a single transaction while minimizing network round-trips.SELECT queries for a reporting endpoint so all queries see a consistent point-in-time view without blocking concurrent writers.Which approach should you implement using the Spanner client libraries?
DatabaseClient for each incoming request, execute each INSERT and UPDATE statement in its own ReadWriteTransaction, and run the reporting SELECT queries independently outside of a transaction.Instantiating and closing a DatabaseClient on every HTTP request forces the application to repeatedly allocate and tear down network connections and Spanner session pools. Running each INSERT, UPDATE, and SELECT independently treats each database call as an isolated, single-operation interaction rather than a coordinated unit of work.
DatabaseClient for every request wastes Spanner resources and adds significant latency from establishing connections and warming up session pools, only to discard them immediately via close().INSERT and UPDATE in its own ReadWriteTransaction means the first operation commits before the second begins. If the second write fails, the first write remains persisted, leaving account balances and transfer logs inconsistent.SELECT queries outside of a read-only transaction (snapshot) allows concurrent updates to commit between the first and second queries, causing the reporting endpoint to combine data from different points in time.DatabaseClient consumes memory, network sockets, and backend Spanner sessions; frequent creation and closure severely degrades throughput under load.A short-lived command-line script or single-purpose batch job ran infrequently, performed only one independent write or single-query read, and needed to clean up all client resources before exiting.
While it is good practice to call close() on unneeded Spanner clients when shutting down an application or retiring a temporary client, production services handling concurrent requests should initialize the client once at startup and reuse it.
DatabaseClient created at startup, use the Mutation API inside a ReadWriteTransaction so writes are immediately visible to subsequent reads in the same transaction, and run the reporting queries inside a ReadWriteTransaction.The Mutation API provides an alternative to DML for inserting, updating, or deleting rows by buffering changes on the client and applying them when the transaction commits. A ReadWriteTransaction is Spanner's read-write execution mode that acquires locks and supports atomic writes alongside strong reads.
ReadWriteTransaction acquires shared read locks that can block or conflict with concurrent writers, increasing transaction aborts and latency when no writes are needed.The write workload needed simple, blind key-value mutations without reading back uncommitted changes mid-transaction, and the reporting endpoint actually needed to perform conditional writes alongside its reads.
Developers often confuse DML and the Mutation API in Spanner. When an application needs to read its own uncommitted writes within a transaction or batch multiple SQL updates efficiently, DML (or Batch DML) is required instead of mutations.
DriverManager.getConnection() per request in autocommit mode, execute the INSERT and UPDATE statements sequentially, and set a gaxOptions timeout longer than the default RPC timeout for the reporting queries.The Spanner JDBC driver enables standard Java Database Connectivity (DriverManager.getConnection()) against Spanner databases. In autocommit mode, every SQL statement is automatically wrapped in its own single-statement transaction and committed immediately. Meanwhile, gaxOptions is a configuration mechanism in the native Spanner client libraries used to adjust per-RPC call settings such as timeouts.
DriverManager.getConnection() for every request without a connection pool repeatedly opens and closes connections, degrading performance under high concurrency.INSERT, UPDATE, and SELECT statements sequentially in autocommit mode runs each statement in a separate transaction. Related writes are not atomic, and reporting queries do not share a consistent point-in-time snapshot.gaxOptions timeouts can only be set shorter than the default RPC timeout. Setting a timeout longer than the default is ignored, and Spanner falls back to the default timeout.SELECT statements may observe different committed states if writers modify rows between queries.gaxOptions RPC timeouts cannot extend beyond the library's built-in default timeout.gaxOptions belongs to native Spanner client libraries rather than standard JDBC Statement calls.An application used a third-party Java framework requiring JDBC with an explicit connection pool, disabled autocommit (setAutoCommit(false)) for atomic writes and read-only transactions, and only needed to shorten RPC timeouts.
When using JDBC with Spanner for multi-statement transactions or consistent multi-query reads, developers must disable autocommit or execute explicit transaction control statements (such as set transaction read only) and pair the driver with a connection pool.
DatabaseClient at application startup and reuse it across requests, execute the writes using Batch DML inside a ReadWriteTransaction, and run the reporting queries inside a read-only transaction (snapshot).In Spanner, the DatabaseClient (or Client) acts as the primary entry point for reading, writing, and managing transactions, internally handling session pooling and gRPC connections. Batch DML (batchUpdate() or BatchUpdate()) groups multiple Data Manipulation Language statements into a single request inside a ReadWriteTransaction, while a read-only transaction (also called a snapshot) executes multiple reads against a fixed point in time without acquiring locks.
DatabaseClient once at application startup and reusing it across requests allows the client library to maintain and share an underlying pool of Spanner sessions and network channels, avoiding expensive setup overhead per request.INSERT and UPDATE statements via Batch DML inside a single ReadWriteTransaction guarantees ACID atomicity (either all statements commit or all roll back) while sending the statements together to reduce client-server round-trips.SELECT queries inside a read-only transaction (snapshot) ensures every query observes the exact same database state, even if concurrent writes occur between queries, without acquiring write locks.DatabaseClient maximizes session cache efficiency and prevents resource exhaustion.ReadWriteTransaction helpers in the client libraries automatically handle transient abort retries.This combination aligns with Spanner's distributed architecture by pairing long-lived client reuse for throughput, Batch DML for atomic multi-statement writes, and read-only snapshots for lock-free, consistent analytical queries.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated