Firebase reads and monetisation

Hey people,

I got into coding like a year and a half ago. I had self-published a foreign language learning book that I wanted to turn into an app. Now I’m at the stage where I’ve pretty much made the initial version of the app.

This is the website for the brand I’ve developing www.drawitbooks.com

So, I’m at the stage where I need to test the app a bit more, and also work out a way to monetise it.

The one thing I’m working my way through at the moment is Firebase(reads). My app uses a Firebase database where it stores a bunch of words to form various ‘dictionaries’ - French, German, Spanish etc.

What I’ve noticed is that if a user(in this instance only me) has the app open in the background then the reads still tick over - even though the app ‘isn’t being used’. (Its like a ‘pulse’ and make about 14 reads every few minutes - I will continue to monitor it and see what happens).

Has anyone got any perspectives on this and how to avoid accruing reads when the app is running in the background? (I started to explore caching - but this seems to only really work if an app is operating offline, right?)

Naturally, my concern with all of this is cost; should my potential userbase grow. So, in addition if anyone has got any experience with monetising their app I’d be keen to here how you got on with the process please - what you used, what did and didn’t work well.

Many thanks,

Chris

Weird that your app is fetching the same doc several times while in the background. It’s most likely due to how you set it up.

Are you using getDocument or a listener?

Honestly I wouldn’t get too concerned with this until you get to at least 100 users. Plus the free tier is already plenty.

Although of course you should solve your issue of needless background document reads

Sup Cal,

I’m using getDocuments.

Think I’m just going to have to do a bunch more testing.

Sup Chris! :slight_smile:

Huh so I’m not sure why your app would keep fetching data from the background.
How do you call the function that sends Firebase the request?

By default Firestore already has a local disk cache. You can access it like this

let docRef = db.collection("cities").document("SF")

do {
  // Force the SDK to fetch the document from the cache. Could also specify
  // FirestoreSource.server or FirestoreSource.default.
  let document = try await docRef.getDocument(source: .cache)
  if document.exists {
    let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
    print("Cached document data: \(dataDescription)")
  } else {
    print("Document does not exist in cache")
  }
} catch {
  print("Error getting document: \(error)")
}

Source:
https://firebase.google.com/docs/firestore/query-data/get-data#swift_3

I’m guessing for a language learning book the data doesn’t change too often, so it wouldn’t be an issue for the phone to try hitting the cache first (up until a certain expiration time maybe?) and if it can’t find the doc, then request the server

Thanks Cal,

Really appreciate this. I’ll have a dabble and see what I can come out with. ‘Data handling’ is far from my strength in this arena. But ‘always learning’ and all that. It makes enough sense that I think I can get it to work.

Take it easy