speedplane
speedplane

Reputation: 16141

App Engine Datastore Pricing: Reads with Large Offsets

For my Google App Engine app, I often need to use large offsets (2000 or more) into the datastore. I know this is not best practice, but I'd like to know the most cost effective way to do these.

Can I use the keys_only feature to make this cost effective?

For example, if I make a keys_only query with an offset of 2000 and limit of 10, then pull the 10 items by their key, I should only be charged 11 datastore reads, correct? If I didn't use keys_only, I'd be charged for 2011 reads, right?

Upvotes: 1

Views: 127

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39834

Indeed, keys_only queries would help, your calculation seems correct. From Pricing and Quota:

Small Operations Unlimited Free

Small operations include calls to allocate Cloud Datastore IDs or keys-only queries.

But in general you might want to switch to using Cursors instead of offsets, for more reasons than just costs. From Offsets versus cursors:

Although Cloud Datastore supports integer offsets, you should avoid using them. Instead, use cursors. Using an offset only avoids returning the skipped entities to your application, but these entities are still retrieved internally. The skipped entities do affect the latency of the query, and your application is billed for the read operations required to retrieve them. Using cursors instead of offsets lets you avoid all these costs.

Upvotes: 1

Related Questions