1) What is Firebase Realtime database?

It is hosted in the cloud document oriented NoSQL database. Data is saved in JSON format and updated in real-time through pus/sub mechanism. The key difference from other DB engines is that, it can be accessed directly from a client (web browser, android/iOS application), also RESTful API available, to control access to sensitive date declarative rules can be used.
 Real-time DB supports offline mode out of the box, all date changed when client was offline will be automatically synchronized with server.

2) What is best practices to structure Firebase DB?

You should avoid deep nesting of your data, because when you retrieve data from some location it returns all sub nodes, moreover it is bad for security because if you grant access to parent node, consequently to all child nodes.
 When needed duplicate your date to provide faster reads.

3) What method are available to manage data?

In JavaScript SDK available such methods:
        - db.getRef('path') to specify node path

        - push({data:1}) to create node at specified path, it returns key of created node immediately

        - update({newData:3}) to partially update all data at specified location

        - set({newData:2}) to overwrite all data at specified location

        - once('value',snapshot=>snapshot.val()) to read data, and subscribe for changes


4) Does firebase support indexes?

Firebase supports indexing data, you should specify indexes in Database rules file. If you try filter data on unspecified index, you will get warning, and Firebase load all data and filter it on client side.

   Index example

   {

    "users":{

        ".indexOn":["email"]

    }

   }

5) How to query data on multiple clauses in firebase?

If you attempt to call orderBy() method twice, Exception will be thrown, because firebase do not support multiple filter parameters.
 Only way is to filter part of data on server side other on manually on client. Or create your own compound indexes.

6)How to get only keys in Firebase?

It is only possible by using Firebase REST API, just add parameter shallow=true.

https://dinosaur-facts.firebaseio.com/dinosaurs.json?shallow=true


7) How to implement pagination?

There is two ways to paginate firebase data, first is to use limitToLast() or limitToFirst() operators, which set maximum number of child nodes to be fetched at specified location. The problem is you can’t get total number of node before you fetch them all. So this way is suitable only for “Load more” functionality.

firebase.database().ref("employees").orderByChild("balance").limitToFirst(10);


Second way is to get total number of rows by using REST API with shallow=true, and then use orderByKey() method combined with startAt() and endAt() methods.

let employees=await db.ref("employees").orderByKey().startAt(firstKey).endAt(lastKey).once('value').then(snapshot => snapshot.val());

The problem way is that you aren't able to filter data bacause shalow=true parameter can't be combined with any operator like startAt or endAt. So you will paginate whole table, if you need search functionality better use limitToFirst functionality

8) What is Firebase cloud functions? 

It is Google analog to AWS Lambda, which is used create serverless apps.
 You write function and specify trigger which should invoke it. There is such type of triggers: pub/sub triggers, HTTP triggers, Firebase storage triggers, Auth triggers, Realtime DB triggers, Firestore triggers. Functions should be implemented using Node.js 

9) How to deploy firebase functions?

To deploy firebase cloud functions, you need install npm package firebase-tools globally.

Then you need run command firebase login in console, change directory to your project repository and run command firebase init functions, and firebase will create minimal cloud function template which is ready to deploy.

Last step is to execute  command.
firebase deploy --only functions