Skip to content
BytePatterns

DVA-C02 · Domain 1: Development with AWS Services · 32% of the exam

Task 1.3: Use data stores in application development

Storing and reading data from code: DynamoDB keys, indexes, query versus scan and read consistency, conditional and transactional writes, serializing items, data lifecycles with TTL and S3 rules, caching with ElastiCache and DAX, and choosing a specialized store such as OpenSearch Service.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the AWS documentation page that proves it.

Question 1 · choose 1

An Amazon DynamoDB table stores sensor readings from 40,000 devices. Its partition key is deviceType, which has four possible values, and its sort key is the reading timestamp. Writes are throttled even though the table uses far less than its total capacity. Every read asks for one device's readings in a time range. Which primary key design fixes the throttling and still serves the reads?

  1. APartition key set to the reading date, rounded to the day; sort key set to deviceId and timestamp
  2. BPartition key set to the reading's status, such as OK, WARN or ERROR; sort key set to the timestamp
  3. CKeep deviceType as the partition key and add a local secondary index on deviceId
  4. DPartition key set to deviceId; sort key set to the timestamp
Show the answer and why
  • APartition key set to the reading date, rounded to the day; sort key set to deviceId and timestamp

    Incorrect

    A creation date rounded to a day is a poor partition key: every write on a given day goes to the same key value.

  • BPartition key set to the reading's status, such as OK, WARN or ERROR; sort key set to the timestamp

    Incorrect

    A status code with only a few possible values concentrates traffic on a few keys, the same problem as deviceType.

  • CKeep deviceType as the partition key and add a local secondary index on deviceId

    Incorrect

    A local secondary index keeps the base table's partition key, so every write still lands on one of the four deviceType values.

  • DPartition key set to deviceId; sort key set to the timestamp

    Correct

    deviceId has many distinct values, so writes spread across partitions, and a Query on one deviceId with a timestamp range serves each read.

Choose a partition key with many distinct, evenly accessed values; low cardinality keys such as types, statuses or dates create hot partitions.

Question 2 · choose 1

An Amazon DynamoDB Orders table has orderId as its partition key and no sort key. A new screen must list one customer's orders from the last 30 days. The first version of the code runs a Scan on the whole table and keeps the matching items in application code, which is slow and consumes a lot of read capacity as the table grows. What should the developer do?

  1. AAdd a global secondary index with customerId and orderDate as keys, and Query it
  2. BKeep the Scan and add a ProjectionExpression that returns only the needed attributes
  3. CKeep the Scan and move the customer and date checks into a FilterExpression
  4. DCreate a local secondary index with customerId as its sort key
Show the answer and why
  • AAdd a global secondary index with customerId and orderDate as keys, and Query it

    Correct

    A global secondary index can have a different key schema from the table, so a Query on one customerId with a sort key condition reads only that customer's recent orders.

  • BKeep the Scan and add a ProjectionExpression that returns only the needed attributes

    Incorrect

    A projection only trims the attributes returned. The Scan still reads every item in the table.

  • CKeep the Scan and move the customer and date checks into a FilterExpression

    Incorrect

    A filter expression is applied after the Scan reads the data, so it consumes the same read capacity.

  • DCreate a local secondary index with customerId as its sort key

    Incorrect

    A local secondary index keeps the table's partition key, orderId, so it cannot find all orders of one customer.

Design for Query: add an index whose keys match the access pattern instead of scanning and filtering.

Question 3 · choose 1

After a user saves a profile change, an application immediately calls GetItem on the Amazon DynamoDB table's primary key to show the new profile. Sometimes the page shows the old values. The read that follows a successful write must always return the latest data. What should the developer change?

  1. ARead the profile from a global secondary index of the table instead
  2. BWait one second before the GetItem call and read again if the data looks old
  3. CSet ConsistentRead to true on the GetItem call
  4. DRead the latest change for the profile from the table's DynamoDB stream
Show the answer and why
  • ARead the profile from a global secondary index of the table instead

    Incorrect

    All reads from a global secondary index are eventually consistent, so they can also return old data.

  • BWait one second before the GetItem call and read again if the data looks old

    Incorrect

    An eventually consistent read should return the newer item after a short time, but nothing guarantees it on any given attempt.

  • CSet ConsistentRead to true on the GetItem call

    Correct

    A strongly consistent read returns the most up-to-date data, reflecting all prior successful writes. Tables and local secondary indexes support it.

  • DRead the latest change for the profile from the table's DynamoDB stream

    Incorrect

    Reads from DynamoDB Streams are eventually consistent, and strongly consistent reads from a stream are not supported.

GetItem, Query and Scan are eventually consistent by default; ConsistentRead set to true gives read-after-write on tables and local secondary indexes, at twice the read cost.

Question 4 · choose 1

Two instances of an inventory service can read the same Amazon DynamoDB item, change its quantity in memory, and write it back with PutItem. Sometimes one instance silently overwrites the other's change. The developer wants a write to fail when the item has changed since it was read, without holding locks. What should the developer do?

  1. ASend both instances' changes in one BatchWriteItem call
  2. BStore a version number and write only if the version is still unchanged
  3. CRead the item with ConsistentRead set to true before every change
  4. DCall PutItem with ReturnValues set to ALL_OLD and compare the old item afterward
Show the answer and why
  • ASend both instances' changes in one BatchWriteItem call

    Incorrect

    Each put or delete in a batch is atomic on its own, but BatchWriteItem as a whole is not, and it does not compare the item with what was read.

  • BStore a version number and write only if the version is still unchanged

    Correct

    This is optimistic locking: the conditional write succeeds only if the version still matches, and a stale writer gets a failed condition check and can reread and retry.

  • CRead the item with ConsistentRead set to true before every change

    Incorrect

    A strongly consistent read returns the latest data at read time, but another writer can still change the item before the PutItem call.

  • DCall PutItem with ReturnValues set to ALL_OLD and compare the old item afterward

    Incorrect

    ALL_OLD returns the item that was replaced, which only shows after the fact that a newer change was overwritten.

Condition expressions make writes conditional; a version attribute turns them into optimistic concurrency control.

Question 5 · choose 1

An application keeps user sessions in an Amazon DynamoDB table. A session should disappear about 24 hours after the user's last activity. Today a scheduled job scans the table and deletes old sessions, which consumes write capacity. The team accepts that an expired item may remain for a while before it is removed. Which solution removes expired sessions without consuming write throughput?

  1. AA Lambda function triggered by the table's stream that deletes each session 24 hours after it is written
  2. BPoint-in-time recovery with a recovery period of 1 day
  3. CA scheduled function that deletes expired sessions with BatchWriteItem in groups of 25
  4. DTime to Live on an expiresAt attribute that holds epoch seconds and is reset on each activity
Show the answer and why
  • AA Lambda function triggered by the table's stream that deletes each session 24 hours after it is written

    Incorrect

    A stream trigger reacts when an item changes, not a day later, and the deletes it issues are ordinary writes.

  • BPoint-in-time recovery with a recovery period of 1 day

    Incorrect

    Point-in-time recovery keeps continuous backups for restoring the table. It does not delete items from the live table.

  • CA scheduled function that deletes expired sessions with BatchWriteItem in groups of 25

    Incorrect

    Batching reduces the number of calls, but each delete in the batch is still a write against the table's capacity.

  • DTime to Live on an expiresAt attribute that holds epoch seconds and is reset on each activity

    Correct

    With TTL enabled, DynamoDB deletes items whose expiration time has passed without consuming write throughput, typically within a few days of expiry.

TTL is the built-in, no-cost way to expire items; store the timestamp as a Number in epoch seconds and filter expired items out of reads if needed.

Question 6 · choose 2

Product pages read product details from an Amazon Aurora database, and reads far outnumber writes. A developer adds an Amazon ElastiCache cache in front of the database. The cache must hold only products that customers actually request, and a cached product may be at most 5 minutes out of date. Which TWO techniques should the developer use? (Choose TWO.)

  1. AWrite every product to the cache each time it is written to the database, with keys that never expire
  2. BPut DynamoDB Accelerator (DAX) in front of the Aurora database
  3. COn a cache miss, read the product from the database and then store it in the cache
  4. DKeep cached items until the cache runs out of memory and evicts them
  5. ESet a time to live of 300 seconds on every key written to the cache
Show the answer and why
  • AWrite every product to the cache each time it is written to the database, with keys that never expire

    Incorrect

    Write-through keeps cached data fresh, but it fills the cache with products that may never be read, which breaks the first requirement.

  • BPut DynamoDB Accelerator (DAX) in front of the Aurora database

    Incorrect

    DAX is a DynamoDB-compatible cache. It caches DynamoDB tables, not an Aurora database.

  • COn a cache miss, read the product from the database and then store it in the cache

    Correct

    Lazy loading loads data into the cache only when it is requested, so products that nobody reads never take up cache space.

  • DKeep cached items until the cache runs out of memory and evicts them

    Incorrect

    Without an expiry, a lazily loaded item is never refreshed after the database changes, so it can stay stale far longer than 5 minutes.

  • ESet a time to live of 300 seconds on every key written to the cache

    Correct

    When a key expires, the next read is treated as a miss and reloads the product from the database, which bounds staleness at 5 minutes.

Lazy loading caches only what is read; adding a TTL to each key limits how stale that data can get.

Question 7 · choose 1

A DynamoDB table in provisioned capacity mode must serve 20 strongly consistent reads per second. Each item is 9 KB. How many read capacity units must the developer provision for these reads?

  1. A20
  2. B30
  3. C45
  4. D60
Show the answer and why
  • A20

    Incorrect

    One RCU covers one strongly consistent read per second only for items up to 4 KB; these items are larger.

  • B30

    Incorrect

    This is what eventually consistent reads would need, at half the strongly consistent rate.

  • C45

    Incorrect

    Dividing 9 KB by 4 KB without rounding up gives 2.25 units per read; capacity is rounded up to whole units.

  • D60

    Correct

    9 KB divided by 4 KB, rounded up, is 3 RCUs per strongly consistent read, and 3 times 20 reads per second is 60.

RCUs use 4 KB steps rounded up per item; eventually consistent reads need half as many.

Question 8 · choose 1

A product catalog is cached in Amazon ElastiCache in front of a relational database. Today the cache is filled only on cache misses, so after a price update, users can see the old price until the cached entry expires. Prices must be current in the cache as soon as they change. Which caching strategy should the developer add?

  1. AWrite-through, updating the cache whenever the database is written
  2. BLazy loading only, with a longer TTL on all of the cached catalog entries
  3. CA larger cache node type with more memory
  4. DMore replicas of the cache cluster for reads
Show the answer and why
  • AWrite-through, updating the cache whenever the database is written

    Correct

    Write-through adds or updates data in the cache every time it is written to the database, so cached data is never stale.

  • BLazy loading only, with a longer TTL on all of the cached catalog entries

    Incorrect

    Lazy loading updates the cache only on misses, and a longer TTL keeps stale prices even longer.

  • CA larger cache node type with more memory

    Incorrect

    More memory holds more entries but does not refresh them when prices change.

  • DMore replicas of the cache cluster for reads

    Incorrect

    Replicas spread read load; they do not update data when the database changes.

Combine write-through with lazy loading and TTLs when data must stay current in the cache.

Question 9 · choose 1

A team runs a MySQL-compatible database for a development and test environment. Load is near zero most of the day and spikes sharply and unpredictably during test runs. The team wants capacity to follow demand automatically and to pay only for the resources it uses. Which option fits?

  1. AAn Amazon RDS for MySQL DB instance of the largest available instance size
  2. BAn Amazon RDS for MySQL DB instance with a read replica
  3. CAn Amazon Aurora MySQL cluster that uses Aurora serverless capacity
  4. DA DynamoDB table in on-demand capacity mode
Show the answer and why
  • AAn Amazon RDS for MySQL DB instance of the largest available instance size

    Incorrect

    A large fixed instance is paid for all day while it sits idle most of the time.

  • BAn Amazon RDS for MySQL DB instance with a read replica

    Incorrect

    A read replica adds read capacity but is another fixed-size instance; capacity does not follow demand.

  • CAn Amazon Aurora MySQL cluster that uses Aurora serverless capacity

    Correct

    Aurora serverless adjusts capacity automatically with demand and is suited to development, test and unpredictable workloads.

  • DA DynamoDB table in on-demand capacity mode

    Incorrect

    DynamoDB is not MySQL-compatible, so the application would need to be rewritten.

For variable, unpredictable relational workloads, Aurora serverless capacity scales with demand.

Question 10 · choose 1

Several workers can finish the same job at almost the same time, and each writes the job's result to Amazon S3 under the key results/{jobId}.json. Only the first result may be stored; later writes for the same key must fail instead of overwriting it. What should the developer do?

  1. ATurn on S3 Versioning so that every write is kept as a version
  2. BCall HeadObject first and write only when the object does not exist
  3. CSend PutObject with the If-None-Match header
  4. DAdd an Object Lock retention period to the bucket
Show the answer and why
  • ATurn on S3 Versioning so that every write is kept as a version

    Incorrect

    Versioning keeps every write as a new version; later writes still become the current object.

  • BCall HeadObject first and write only when the object does not exist

    Incorrect

    Two workers can both see no object and then both write, because the check and the write are separate requests.

  • CSend PutObject with the If-None-Match header

    Correct

    If-None-Match makes S3 accept the write only when no object with the same key exists, which prevents overwrites.

  • DAdd an Object Lock retention period to the bucket

    Incorrect

    Object Lock protects object versions from deletion and overwrite of those versions, but new versions can still be written for the key.

S3 conditional writes give atomic create-only semantics without a separate locking service.

Question 11 · choose 1

An application uses a single Amazon RDS for PostgreSQL DB instance. The business wants the database to keep running if the instance's Availability Zone fails, with automatic failover and no data loss from replication lag. Read scaling is not needed. What should the developer configure?

  1. AA read replica in another Availability Zone, promoted by a script on failure of the primary
  2. BA Multi-AZ DB instance deployment with a standby in another Availability Zone
  3. CDaily automated snapshots copied to another Region
  4. DA larger instance class with more vCPUs and memory
Show the answer and why
  • AA read replica in another Availability Zone, promoted by a script on failure of the primary

    Incorrect

    Read replicas are updated asynchronously, so recent writes can be lost, and promotion is not automatic failover.

  • BA Multi-AZ DB instance deployment with a standby in another Availability Zone

    Correct

    RDS keeps a synchronous standby in another Availability Zone and fails over to it automatically.

  • CDaily automated snapshots copied to another Region

    Incorrect

    Restoring a snapshot is a manual recovery that loses data written since the snapshot.

  • DA larger instance class with more vCPUs and memory

    Incorrect

    A bigger instance still runs in one Availability Zone.

Multi-AZ standbys provide high availability; they do not serve reads, for which read replicas are used.

Practise domain 1 →Practise all domains →