title: Firebase (Google) Cloud Functions - Debounce/Throttle database.onWrite() #AskFirebase
body: <h3>Scenario</h3>
  
  <p>I have documents stored for each user at path <code>documents/${documentId}</code></p>
  
  <h3>Goal</h3>
  
  <p>I want to parse them and update the index for that document when it changes</p>
  
  <h3>Code</h3>
  
  <pre><code>import Functions from 'firebase-functions'
  
  export writeTrigger = Functions
    .database
    .ref('/document/{documentId}')
    .onWrite(
      async event =&gt; {
        const data = event.data.val()
        const { documentId } = event.params
        // assume that updateIndex function exists
        updateIndex(documentId, data)
      }
    )
  </code></pre>
  
  <h3>Problem</h3>
  
  <p>This function gets called for every single letter being typed into the document</p>
  
  <h2>TLDR</h2>
  
  <p>What is the best way to throttle/debounce firebase cloud functions (database.onWrite) so that it isn't fired on each and every change?</p>