All topics

Google Cloud interview questions

17 questions with answers. 2,108 open jobs in India ask for Google Cloud.

  1. What is the difference between Google App Engine and Google Compute Engine?

    App Engine is a Platform-as-a-Service. It means that you simply deploy your code, and the platform does everything else for you. For example, if your app becomes very successful, App Engine will automatically create more instances to handle the increased volume.

    Read more about App Engine

    Compute Engine is an Infrastructure-as-a-Service. You have to create and configure your own virtual machine instances. It gives you more flexibility and generally costs much less than App Engine. The drawback is that you have to manage your app and virtual machines yourself.

    Read more about Compute Engine

    You can mix both App Engine and Compute Engine, if necessary. They both work well with the other parts of the Google Cloud Platform.

    EDIT (May 2016):

    One more important distinction: projects running on App Engine can scale down to zero instances if no requests are coming in. This is extremely useful at the development stage as you can go for weeks without going over the generous free quota of instance-hours. Flexible runtime (i.e. "managed VMs") require at least one instance to run constantly.

    EDIT (April 2017):

    Cloud Functions (currently in beta) is the next level up from App Engine in terms of abstraction - no instances! It allows developers to deploy bite-size pieces of code that execute in response to different events, which may include HTTP requests, changes in Cloud Storage, etc.

    The biggest difference with App Engine is that functions are priced per 100 milliseconds, while App Engine's instances shut down only after 15 minutes of inactivity. Another advantage is that Cloud Functions execute immediately, while a call to App Engine may require a new instance - and cold-starting a new instance may take a few seconds or longer (depending on runtime and your code).

    This makes Cloud Functions ideal for (a) rare calls - no need to keep an instance live just in case something happens, (b) rapidly changing loads where instances are often spinning and shutting down, and possibly more use cases.

    Read more about Cloud Functions

    From Stack Overflow: asked by Cameron Brown, answered by Andrei Volgin (CC BY-SA 3.0)

  2. What's the difference between Cloud Firestore and the Firebase Realtime Database?

    I wrote an entire blog post all about this very question, and I recommend you check it out (or the official documentation) for a more complete answer.

    But if you want the quick(-ish) summary, here it is:

    Better querying and more structured data -- While the Realtime Database is just a giant JSON tree, Cloud Firestore is a little more structured. All your data consists of documents (which are basically key-value stores) and collections (which are collections of documents). Documents will also frequently point to subcollections, which contain other documents, which themselves can contain other documents, and so on.

    This structured data helps you out in two ways. First, all queries are shallow, meaning that you can request a document without grabbing all the data underneath. This means you can keep your data stored hierarchically in a way that makes more sense to you without having to worry about keeping your database shallow. Second, you have more powerful queries. For instance, you can now query across multiple fields without having to create those "combo" fields that combine (and denormalize) data from other parts of your database. In some cases, Cloud Firestore will just run those queries directly, and in other cases, it will automatically create and maintain indexes for you.

    Designed to Scale -- Cloud Firestore will be able to scale better than the Realtime Database. It's important to note that your queries scale to the size of your result set, not your data set. So searching will remain fast no matter how large your data set might become.

    Easier manual fetching of data -- Like the Realtime Database, you can set up listeners in Cloud Firestore to stream in changes in real-time. But if you don't want that kind of behavior, and just want a simple "fetch my data" call, Cloud Firestore has that as well, and it's built in as a primary use case. (They're much better than the once calls in Realtime Database-land)

    Multi region support -- This basically means more reliability, as your data is shared across multiple data centers at once. But you still have strong consistency, meaning you can always make a query and be assured that you're getting the latest version of your data.

    Different pricing model -- While the Realtime Database primarily charges based on storage or network bandwidth, Cloud Firestore primarily charges based on the number of operations you perform. Will this be better, or worse? It depends on your app.

    For powering a news app, turn-based multiplayer game, or something like your own version of Stack Overflow, Cloud Firestore will probably look pretty favorable from a pricing standpoint. For something like a real-time group drawing app where you're sending across multiple updates a second to multiple people, it probably will be more expensive than the Realtime Database.

    Why you still might want the to use the Realtime Database -- It comes down to a few reasons.

    1. That whole "it'll probably be cheaper for apps that make lots of frequent updates" thing I mentioned previously,

    2. It's been around for a long time and has been battle tested by thousands of apps,

    3. It's got better latency and when you need something with reliably low latency for a real-timey feel, the Realtime Database might work better.

    For most new apps, we recommend you check out Cloud Firestore. But if you have an app that's already on the Realtime Database, I don't really recommend switching just for the sake of switching, unless you have a compelling reason to do so.

    From Stack Overflow: asked by Francisco Durdin Garcia, answered by Todd Kerpelman (CC BY-SA 4.0)

  3. What is Firebase Firestore 'Reference' data type good for?

    References are very much like foreign keys.

    The currently released SDKs cannot store references to other projects. Within a project, references can point to any other document in any other collection.

    You can use references in queries like any other value: for filtering, ordering, and for paging (startAt/startAfter).

    Unlike foreign keys in a SQL database, references are not useful for performing joins in a single query. You can use them for dependent lookups (which seem join like), but be careful because each hop will result in another round trip to the server.

    From Stack Overflow: asked by Jürgen Brandstetter, answered by Gil Gilbert (CC BY-SA 4.0)

  4. Is gRPC(HTTP/2) faster than REST with HTTP/2?

    gRPC is not faster than REST over HTTP/2 by default, but it gives you the tools to make it faster. There are some things that would be difficult or impossible to do with REST.

    • Selective message compression. In gRPC a streaming RPC can decide to compress or not compress messages. For example, if you are streaming mixed text and images over a single stream (or really any mixed compressible content), you can turn off compression for the images. This saves you from compressing already compressed data which won't get any smaller, but will burn up your CPU.
    • First class load balancing. While not an improvement in point to point connections, gRPC can intelligently pick which backend to send traffic to. (this is a library feature, not a wire protocol feature). This means you can send your requests to the least loaded backend server without resorting to using a proxy. This is a latency win.
    • Heavily optimized. gRPC (the library) is under continuous benchmarks to ensure that there are no speed regressions. Those benchmarks are improving constantly. Again, this doesn't have anything to do with gRPC the protocol, but your program will be faster for having used gRPC.

    As nfirvine said, you will see most of your performance improvement just from using Protobuf. While you could use proto with REST, it is very nicely integrated with gRPC. Technically, you could use JSON with gRPC, but most people don't want to pay the performance cost after getting used to protos.

    From Stack Overflow: asked by Lakshman Diwaakar, answered by Carl Mastrangelo (CC BY-SA 4.0)

  5. Choosing Java vs Python on Google App Engine

    I'm biased (being a Python expert but pretty rusty in Java) but I think the Python runtime of GAE is currently more advanced and better developed than the Java runtime -- the former has had one extra year to develop and mature, after all.

    How things will proceed going forward is of course hard to predict -- demand is probably stronger on the Java side (especially since it's not just about Java, but other languages perched on top of the JVM too, so it's THE way to run e.g. PHP or Ruby code on App Engine); the Python App Engine team however does have the advantage of having on board Guido van Rossum, the inventor of Python and an amazingly strong engineer.

    In terms of flexibility, the Java engine, as already mentioned, does offer the possibility of running JVM bytecode made by different languages, not just Java -- if you're in a multi-language shop that's a pretty large positive. Vice versa, if you loathe Javascript but must execute some code in the user's browser, Java's GWT (generating the Javascript for you from your Java-level coding) is far richer and more advanced than Python-side alternatives (in practice, if you choose Python, you'll be writing some JS yourself for this purpose, while if you choose Java GWT is a usable alternative if you loathe writing JS).

    In terms of libraries it's pretty much a wash -- the JVM is restricted enough (no threads, no custom class loaders, no JNI, no relational DB) to hamper the simple reuse of existing Java libraries as much, or more, than existing Python libraries are similarly hampered by the similar restrictions on the Python runtime.

    In terms of performance, I think it's a wash, though you should benchmark on tasks of your own -- don't rely on the performance of highly optimized JIT-based JVM implementations discounting their large startup times and memory footprints, because the app engine environment is very different (startup costs will be paid often, as instances of your app are started, stopped, moved to different hosts, etc, all trasparently to you -- such events are typically much cheaper with Python runtime environments than with JVMs).

    The XPath/XSLT situation (to be euphemistic...) is not exactly perfect on either side, sigh, though I think it may be a tad less bad in the JVM (where, apparently, substantial subsets of Saxon can be made to run, with some care). I think it's worth opening issues on the Appengine Issues page with XPath and XSLT in their titles -- right now there are only issues asking for specific libraries, and that's myopic: I don't really care HOW a good XPath/XSLT is implemented, for Python and/or for Java, as long as I get to use it. (Specific libraries may ease migration of existing code, but that's less important than being able to perform such tasks as "rapidly apply XSLT transformation" in SOME way!-). I know I'd star such an issue if well phrased (especially in a language-independent way).

    Last but not least: remember that you can have different version of your app (using the same datastore) some of which are implemented with the Python runtime, some with the Java runtime, and you can access versions that differ from the "default/active" one with explicit URLs. So you could have both Python and Java code (in different versions of your app) use and modify the same data store, granting you even more flexibility (though only one will have the "nice" URL such as foobar.appspot.com -- which is probably important only for access by interactive users on browsers, I imagine;-).

    From Stack Overflow: asked by Viet, answered by Alex Martelli (CC BY-SA 2.5)

  6. Google Cloud Bigtable vs Google Cloud Datastore

    Based on experience with Datastore and reading the Bigtable docs, the main differences are:

    • Bigtable was originally designed for HBase compatibility, but now has client libraries in multiple languages. Datastore was originally more geared towards Python/Java/Go web app developers (originally App Engine)
    • Bigtable is 'a bit more IaaS' than Datastore in that it's not 'just there' but requires a cluster to be configured.
    • Bigtable supports only one index - the 'row key' (the entity key in Datastore)
      • This means queries are on the Key, unlike Datastore's indexed properties
    • Bigtable supports atomicity only on a single row - there are no transactions
    • Mutations and deletions appear not to be atomic in Bigtable, whereas Datastore provides eventual and strong consistency, depending on the read/query method
    • The billing model is very different:
      • Datastore charges for read/write operations, storage and bandwidth
      • Bigtable charges for 'nodes', storage and bandwidth

    From Stack Overflow: asked by Andrei F, answered by tx802 (CC BY-SA 4.0)

  7. Is It Possible To Get The ID Before It Was Added?

    This is covered in the documentation. See the last paragraph of the add a document section.

    DocumentReference ref = db.collection("my_collection").doc();
    String myId = ref.id;
    

    From Stack Overflow: asked by Tal Barda, answered by 34m0 (CC BY-SA 4.0)

  8. What is the difference between Cloud Functions and Firebase Functions?

    There is no product called Firebase Functions.

    There are three separate things:

    1. Google Cloud Functions, which allow you to run snippets of code in Google's infrastructure in response to events.
    2. Cloud Functions for Firebase, which triggers Google Cloud Functions based on events in Firebase (such as database or file writes, user creation, etc)
    3. Firebase SDK for Cloud Functions, which includes a library (confusingly called firebase-functions) that you use in your Functions code to access Firebase data (such as the snapshot of the data that was written to the database)

    So Firebase provides a (relatively thin) wrapper around Google Cloud Functions, to make the latter product easier to use and integrate it with Firebase. In that senses it is similar to how Firebase integrates Google Cloud Storage into "Cloud Storage for Firebase" (formerly known as Firebase Storage).

    If you're using Google Cloud Platform without Firebase, then you should use plain Google Cloud Functions. If you're on Firebase or if you're a mobile developer interested in Cloud Functions, you should use Cloud Functions for Firebase.

    From Stack Overflow: asked by Muhammad chhota, answered by Frank van Puffelen (CC BY-SA 4.0)

  9. Difference between "gcloud auth application-default login" and "gcloud auth login"

    The difference is the use cases:

    As a developer, I want to interact with GCP via gcloud.
    gcloud auth login
    This obtains your credentials and stores them in ~/.config/gcloud/. Now you can run gcloud commands from your terminal and it will find your credentials automatically. Any code/SDK will not automatically pick up your creds in this case.

    Reference: https://cloud.google.com/sdk/gcloud/reference/auth/login

    As a developer, I want my code to interact with GCP via SDK.
    gcloud auth application-default login
    This obtains your credentials via a web flow and stores them in 'the well-known location for Application Default Credentials'. Now any code/SDK you run will be able to find the credentials automatically. This is a good stand-in when you want to locally test code which would normally run on a server and use a server-side credentials file.

    Reference: https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login

    Edit (09/19/2019):
    As Kent contributed in his comment below, 'the well-known location for Application Default Credentials' is a file named application_default_credentials.json located in your local ~/.config/gcloud/ directory. I've added an additional link below to an article by Theodore Sui and Daniel De Leo which goes into greater detail about the different authentication methods.

    Article: https://medium.com/google-cloud/local-remote-authentication-with-google-cloud-platform-afe3aa017b95

    From Stack Overflow: asked by Marshall An, answered by Himal (CC BY-SA 4.0)

  10. What's the difference between BigQuery and Bigtable?

    The difference is basically this:

    BigQuery is a query Engine for datasets that don't change much, or change by appending. It's a great choice when your queries require a "table scan" or the need to look across the entire database. Think sums, averages, counts, groupings. BigQuery is what you use when you have collected a large amount of data, and need to ask questions about it.

    BigTable is a database. It is designed to be the foundation for a large, scaleable application. Use BigTable when you are making any kind of app that needs to read and write data, and scale is a potential issue.

    From Stack Overflow: asked by The user with no hat, answered by Michael Manoochehri (CC BY-SA 3.0)

  11. When should I choose App Engine over Cloud Functions?

    Cloud Functions (CFs) and Google App Engine (GAE) are different tools for different jobs. Using the right tool for the job is usually a good idea.

    Driving a nail using pliers might be possible, but it won't be as convenient as using a hammer. Similarly building a complex app using CFs might be possible, but building it using GAE would definitely be more convenient.

    CFs have several disadvantages compared to GAE (in the context of building more complex applications, of course):

    • they're limited to Node.js, Python, Go, Java, .NET Core, and Ruby. GAE supports several other popular programming languages
    • they're really designed for lightweight, standalone pieces of functionality, attempting to build complex applications using such components quickly becomes "awkward". Yes, the inter-relationship context for every individual request must be restored on GAE just as well, only GAE benefits from more convenient means of doing that which aren't available on CFs. For example user session management, as discussed in other comments
    • GAE apps have an app context that survives across individual requests, CFs don't have that. Such context makes access to certain Google services more efficient/performant (or even plain possible) for GAE apps, but not for CFs. For example memcached.
    • the availability of the app context for GAE apps can support more efficient/performant client libraries for other services which can't operate on CFs. For example accessing the datastore using the ndb client library (only available for standard env GAE python apps) can be more efficient/performant than using the generic datastore client library.
    • GAE can be more cost effective as it's "wholesale" priced (based on instance-hours, regardless of how many requests a particular instance serves) compared to "retail" pricing of CFs (where each invocation is charged separately)
    • response times might be typically shorter for GAE apps than CFs since typically the app instance handling the request is already running, thus:
      • the GAE app context doesn't need to be loaded/restored, it's already available, CFs need to load/restore it
      • (most of the time) the handling code is already loaded; CFs' code still needs to be loaded. Not too sure about this one; I guess it depends on the underlying implementation.

    From Stack Overflow: asked by stkvtflw, answered by Dan Cornilescu (CC BY-SA 4.0)

  12. What to do with Released persistent volume?

    As documented here, "Delete the claimRef entry from PV specs, so as new PVC can bind to it. This should make the PV Available."

    So do the following:

    kubectl patch pv pv-for-rabbitmq -p '{"spec":{"claimRef": null}}'
    

    This worked for me.

    From Stack Overflow: asked by oldhomemovie, answered by Bharat Chhabra (CC BY-SA 4.0)

  13. What is the difference between Google Cloud Dataflow and Google Cloud Dataproc?

    Yes, Cloud Dataflow and Cloud Dataproc can both be used to implement ETL data warehousing solutions.

    An overview of why each of these products exist can be found in the Google Cloud Platform Big Data Solutions Articles

    Quick takeaways:

    • Cloud Dataproc provides you with a Hadoop cluster, on GCP, and access to Hadoop-ecosystem tools (e.g. Apache Pig, Hive, and Spark); this has strong appeal if you are already familiar with Hadoop tools and have Hadoop jobs
    • Cloud Dataflow provides you with a place to run Apache Beam based jobs, on GCP, and you do not need to address common aspects of running jobs on a cluster (e.g. Balancing work, or Scaling the number of workers for a job; by default, this is automatically managed for you, and applies to both batch and streaming) -- this can be very time consuming on other systems
      • Apache Beam is an important consideration; Beam jobs are intended to be portable across "runners," which include Cloud Dataflow, and enable you to focus on your logical computation, rather than how a "runner" works -- In comparison, when authoring a Spark job, your code is bound to the runner, Spark, and how that runner works
      • Cloud Dataflow also offers the ability to create jobs based on "templates," which can help simplify common tasks where the differences are parameter values

    From Stack Overflow: asked by KosiB, answered by Andrew Mo (CC BY-SA 3.0)

  14. How to change the project in GCP using CLI commands?
    gcloud config set project $MY_PROJECT_ID
    #=>
    Updated property [core/project].
    

    You may also set the environment variable $CLOUDSDK_CORE_PROJECT.

    From Stack Overflow: asked by Ebin Davis, answered by Zachary Newman (CC BY-SA 4.0)

  15. How to open a specific port such as 9090 in Google Compute Engine?

    You need to:

    1. Go to cloud.google.com

    2. Go to my Console

    3. Choose your Project

    4. Choose Networking > VPC network

    5. Choose "Firewall"

    6. Choose "Create Firewall Rule"

    7. To apply the rule to select VM instances, select Targets > "Specified target tags", and enter into "Target tags" the name of the tag. This tag will be used to apply the new firewall rule onto whichever instance you'd like. Then, make sure the instances have the network tag applied.

    8. Set Source IP ranges to allow traffic from all IPs: 0.0.0.0/0

    9. To allow incoming TCP connections to port 9090, in "Protocols and Ports", check “tcp” and enter 9090

    10. Click Create (or click “Equivalent Command Line” to show the gcloud command to create the same rule)

    Update Please refer to docs to customize your rules.

    From Stack Overflow: asked by Subhradip Bose, answered by Carlos Rojas (CC BY-SA 4.0)

  16. Enabling CORS in Cloud Functions for Firebase

    For Cloud Functions v2:

    You can simply define the function to accept CORS requests as shown in the documentation:

    const { onRequest } = require("firebase-functions/v2/https");
    exports.sayHello = onRequest(
      { cors: true },
      (req, res) => {
        res.status(200).send("Hello world!");
      }
    );
    

    For Cloud Functions v1:

    There are two sample functions provided by the Firebase team that demonstrate the use of CORS:

    The second sample uses a different way of working with cors than you're currently using.

    Consider importing like this, as shown in the samples:

    const cors = require('cors')({origin: true});
    

    And the general form of your function will be like this:

    exports.fn = functions.https.onRequest((req, res) => {
        cors(req, res, () => {
            // your function body here - use the provided req and res from cors
        })
    });
    

    From Stack Overflow: asked by Andrey Pokrovskiy, answered by Doug Stevenson (CC BY-SA 4.0)

  17. How to use Google App Engine with my own naked domain (not subdomain)?

    [Update April 2016] This answer is now outdated, custom naked domain mapping is supported, see Lawrence Mok's answer.

    I have figured it out!

    First off: it is impossible to link something like mydomain.example with your appspot app. This is considered a naked domain, which is not supported by Google App Engine (anymore). Strictly speaking, the answer to my question has to be "impossible". Read on...

    All you can do is add subdomains pointing to your app, e.g myappid.mydomain.example. The key to get your top level domain linked to your app is to realize that www is a subdomain like any other!

    myappid.mydomain.example is treated exactly the same as www.mydomain.example!

    Here are the steps:

    1. Go to appengine.google.com, open your app
    2. Administration > Versions > Add Domain... (your domain has to be linked to your Google Apps account, follow the steps to do that including the domain verification.)
    3. Go to www.google.com/a/yourdomain.example
    4. Dashboard > your app should be listed here. Click on it.
    5. myappid settings page > Web address > Add new URL
    6. Simply enter www and click Add
    7. Using your domain hosting provider's web interface, add a CNAME for www for your domain and point to ghs.googlehosted.com

    Now you have www.mydomain.example linked to your app.

    I wished this would have been more obvious in the documentation.

    From Stack Overflow: asked by Mark, answered by Mark (CC BY-SA 4.0)

Related topics

Where these questions come from

Open-source collections on GitHub, official documentation, a government careers service and the Stack Exchange sites, each used under its own licence. The answers are the authors' own words: we only tidy the layout, leave out pictures, and cut a long answer with a link to the rest. Stack Exchange answers stay under CC BY-SA and name who asked and who answered.