JUSTIN BECKWITH: Welcome, and thanks for coming.
Today we're going to talk about running Node.js applications
on Google Cloud Platform.
We're going to take a look at Google Cloud, build a few apps,
and learn about using Google's advanced APIs and services
with your applications.
But before we dive in, a little bit about myself.
My name is Justin Beckwith, and I'm a product manager here
at Google.
My contact information is available here,
so feel free to reach out at any time
if you have questions or feedback about running Node.js
applications on Google Cloud Platform.
As someone who spent years as a web developer,
I've found that there's a lot to like about Node.js.
Many developers spend years writing JavaScript
for fun and web applications.
One of the best parts of Node.js is that it's just JavaScript.
The same skills you use to develop applications
in the browser can be used to develop amazing applications
in the cloud as well.
It's easy to get ramped up, as the core of Node.js
is very small.
Many of the libraries are going to use our open source
and have been developed by community.
Last month, there were over 4 billion packages
downloaded through NPM, the Node.js package manager.
This is a sign of a community that's growing.
As the Node.js community continues to grow,
it's becoming a great destination
for enterprise focused web applications.
Node.js offers a mature API and an LTS release schedule that
provides 18 months of support.
Over that same time, Google Cloud Platform
has also grown and become a great destination
for web applications and APIs that need Google scale.
Node.js is built on V8, the same JavaScript engine
that powers Google Chrome.
We have years of experience tuning JavaScript engines
to provide incredible performance in the browser.
And now we're helping deliver that same incredible
performance in the cloud.
Google Cloud Platform is also easy to use.
You can bring your code and let us
handle the scale and the ops.
Finally, we offer a variety of APIs and services
that allow you to take advantage of Google's incredible big data
and machine learning technology.
The same infrastructure in APIs that
make it possible to run services like Google Search, Gmail,
and Google Photos are all now at your fingertips,
helping you bring your applications to life.
There are three easy ways to run your applications
on Google Cloud.
App Engine is Google's powerful, easy to use
platform as a service.
You bring your code and we'll handle the rest.
App Engine will automatically scale your application
to handle spikes in traffic, provide no-downtime upgrades,
and make it easy to take advantage
of our advanced diagnostics tools and production.
Container Engine is a hosted version
of Kubernetes, which brings Google's container
orchestration technology to the cloud.
It's incredibly powerful for applications that are already
built on top of Docker.
And finally, if you need complete control
and flexibility, Compute Engine offers
traditional virtual machines that you
can manage and control.
Now that we know a little bit about Google Cloud and Node.js,
let's build a simple web application
and deploy it to App Engine.
You can get started using any Node.js framework you'd like,
but today we're going to use Express,
a very common module used for building web applications
and APIs.
I'm going to start by scaffolding a new web
application using Express.
We're going to install our dependencies locally and take
a quick look at the app in action.
This is a simple application.
Now let's get it up and running on App Engine.
To get started, you need to create a new project
in the Google Cloud developer console.
I'm going to deploy to a project I created earlier
using the Google Cloud SDK.
The gcloud preview app deploy command
will publish your code to Google App Engine,
install any NPM dependencies in your package.json,
and start your app.
Under the hood, we're creating cloud load balancers,
virtual machines, auto scalers, managed instance groups,
virtual networks, everything you need
to build a great performing application with a great SLA.
Now that our application has been deployed,
let's check it out.
I'm going to run gcloud preview app browse to take a look
at my site in production.
And here you have it, a simple Node.js application
with Express running on Google App Engine.
Now up to this point, we've been using the Cloud SDK
to work on our app.
Let's take a look at how we can use the Google Cloud developer
console to help manage it.
Here we can see the App Engine dashboard,
which provides a heads-up view of our application performance
metrics.
There's a lot to explore with App Engine,
but some of the most useful features
I want to talk about today are under the Versions
tab in the developer console.
App Engine makes it easy to simultaneously run
multiple versions of your application.
This is useful in a few situations.
First, it's great for performing no-downtime deployments,
where you want to test a new version of your app
before sending any users to the new deployment.
You can see that I have a few versions of this app already
deployed.
Here's the new version we just deployed,
and the previous version we were running.
This is a great feature if you need high availability
and no-downtime upgrades.
In our case, we were routing 100% of our traffic
to a new version.
But what if you want to gradually roll out
your changes?
Or what if you want to perform AB testing and route
different users to distinct versions of your application?
Traffic splitting makes enabling these kinds of setups simple.
As we saw, getting started with Node.js on App Engine
is really easy.
You can bring your code and let us run it
on Google's infrastructure.
You can automatically scale to millions
of requests per second, and you don't need to have downtime
during your deployments.
Now you may be wondering, what if I decide
to use Container Engine, or I want to move my application
on-premise?
Well, I've got great news.
The same Docker image we used to run your application on App
Engine can be used with Container Engine,
or Kubernetes, or any other service that
can run Docker containers.
Our last application was really simple.
It was just a single web application
with no real backend.
In reality, our apps are rarely this simple.
They're often more complex, because the problems
we're trying to solve for our customers are also complex.
We need databases like MongoDB, Postgres, or Datastore
to store our content.
We need message queues for connecting services.
We need advanced services, like the Cloud Vision API and Cloud
ML to help us understand the world around us.
We use advanced tools like BigQuery and Data Flow
to process millions of records to gain valuable insights
on our products.
On Google Cloud Platform, you can combine all of these.
Google products, open source products,
managed services, bring your own,
use what you want to build the experiences
that your customers need.
When you're ready to take advantage of Google's APIs
and services, you can use the gcloud NPM module.
This NPM module gives you access to over a dozen Google
APIs and services, with more on the way.
It works from within App Engine, Kubernetes, Compute Engine,
even from applications that aren't deployed to Google Cloud
Platform.
In my experience, these are the services
that make Google magic.
Containers, the Cloud Vision API,
BigQuery, Machine Learning.
We can use these amazing technologies
to build applications that serve billions of people
all over the planet.
Let's take a look at how you can use these to get started.
Next, we're going to take a look at a fun little Node.js
application that uses the gcloud NPM module.
This app uses App Engine, Cloud Storage, the Cloud Vision API,
and Cloud Pub/Sub to analyze images from the internet,
separate them into pictures of dogs on the right,
and cats on the left.
So now let's take a look at how we
can use these APIs with the gcloud NPM module
to build this kind of application.
To store our images, we're using Google Cloud Storage.
Cloud storage provides a scalable file store,
great for images, videos, or other large files that you want
to keep out of your database.
Using the Cloud Storage API is simple.
You can even use it to serve static HTTP content.
Next up is the Cloud Vision API.
Using this simple service, with five lines of code,
we can detect common labels, landmarks,
and even facial expressions within an image
almost instantaneously.
Finally, we're using Cloud Pub/Sub
to send messages between the microservices that
make up this application.
Cloud Pub/Sub provides low latency durable messaging
between services or devices.
Using these APIs, we can take advantage of technology
that's been in development at Google for years.
Whether it's our machine learning technology, databases,
or big data tools, we have services
that make building amazing applications fast and scalable.
Of course, sometimes you're going to run into trouble.
We've all been in a situation where
code works great on our machines,
but for one reason or another, starts giving us
trouble in production.
Traditionally, debugging these kinds of problems
has been very difficult. But with the Stackdriver
diagnostics tools, we can dig deep
into performance and quality issues in production.
Let's take a look at Stackdriver Trace in action.
In the developer console, I'm going
to navigate to the Trace UI.
This will show an overview of the overall latency
for requests to my HTTP endpoints.
I'm going to drill into the Traces view, which
provides a detailed breakdown of every single outgoing HTTP
and RPC call coming from my app.
As you can see, this last request took around 10 seconds.
That's a long time.
Let's find out why.
I can see that we're downloading a lot of images
to run through the Cloud Vision API.
You can see every request we're making
to download images, upload them to cloud storage,
and analyze them with the Cloud Vision API.
You can even click on a request to get a drill-down view that
shows the origin of the request in your application source
code.
This is a great way to diagnose performance issues
in production.
But what if instead of a performance issue
you're facing a crash?
Stackdriver Debugger makes it easy to analyze
the state of your application in production.
The debug console allows you to set breakpoints
in your production code.
Now, this isn't a traditional breakpoint.
When a request hits this code path,
it will analyze the state of your application
passively, allowing you to capture state without affecting
performance in production.
In review, Stackdriver diagnostic tools
make it easy to diagnose issues in production.
We looked at Trace and Debug, but there
are a variety of other tools at your disposal as well.
Today we covered a lot.
We looked at how App Engine is making
it easy to operate at Google Scale.
We looked at using Google's APIs and services
to build amazing applications.
We diagnosed problems in production,
and of course, we talked about how Google Cloud and Node.js
are a great match.
Everything we looked at today is open source.
The Docker images we used to build the Node.js
runtime, the gcloud NPM module, the Trace and Debug tools,
these are all open source and available on GitHub.
I'd like to thank you again for coming.
And as I mentioned, please feel free to reach out
if you have any questions.
You can learn more about building Node.js applications
on Google Cloud Platform at cloud.google.com/nodejs.