/ New Features

Fly + Now: Fast and Tidy 'Serverless' Deployments

Fly is no stranger to delivering serverless backends and applications. Within our articles, we've gone over AWS Lambda and Google Cloud Functions. Both services allow you to write compartmentalized functions that invoke to address specific contexts. Woven into your application, you might have a serverless function that compresses images, for example. Today, we're happy to announce another serverless-type offering: Now by Zeit.

This article is going to introduce Now, compare it to other 'serverless' backend offerings, then roll through setup within Fly. No servers required, but you should bring a smile. :)

Serenity Now!

Now is under development by the team that's brought the JavaScript community two popular tools: Socket.io and Mongoose. While developing 'web-scale' products they learned that quality often hinges upon the ability to successfully deploy new products, updates, and features. The less friction there is for developers to get stuff done, the better the products will be. Now is the vision for fast deployments with an intuitive and enjoyable developer experience.

In essence, Now abstracts away the "shopping" required when looking for a place to host your JavaScript applications. Whether you're hosting static page, a single page application using React, Ember, or Meteor, an API service through Micro, Express, or Vapor, or something fun like a Slack bot, you'll need to decide where and how you're going to host it. You might choose between the major cloud providers: Amazon, Google, or Azure. Now removes the burden of choice:

1: Install now via the command line.
2: Run 'now' in any project directory with a package.json or Dockerfile.
3: Set-up an alias.
4: Receive a URL for your deployment.
5: Put your URL in-front of your visitors.

For each deployment, if you want to deploy somewhere specific or as a specific function type, you can use the Now Universal API to deploy wherever you wish. Want to deploy your function using AWS Lambda and API Gateway? Or, perhaps using Google Cloud Functions on GCP? Specify your preferences in a now.json file within your project.

Not only streamlining the deployment process, they promise that each deployment will travel over only secure connections and utilize HTTP/2. Mysteriously neat!

Baked into the above example is one key benefit: you can avoid vendor lock-in. You're free to move your code wherever you please - you didn't have to modify your code or use a proprietary API to account for using the service.

Why Now?

With options like AWS Lambda and Google Cloud Functions, what makes Now standout?

We'll look at two reasons:

1: Fully Functional: Mentioned earlier, you can host a variety of JavaScript applications. From single page applications to isolated functions, the choice is yours. The major providers want you to upload context-bound functions that adhere to specific usage patterns. AWS Lambda, for example, requires you to write a handler to speak with Amazon during the invocation of your function. With Now, that isn't required. So long as it's JavaScript, you can host it.

2: Metadata: Your Now requests are clean HTTP requests that respond as you'd expect them to. The metadata that wraps each request is available to your application. Within Fly, this is of particular importance. If you're using Geo-IP Middleware, for example, that header information can make its way directly to your Now backend in-tact. More typically, you can act upon values from Content-Type or User-Agent.

Now Fly

Fly is an Application Delivery Network. You can add a hostname then attach any number of backends to that hostname. For example, you can host a static marketing site on your root domain, a Heroku application on /app/, a Ghost Blog on /blog and a Now-hosted API on /api/. Want Google Cloud Functions, AWS Lambda, and Now applications as disparate microservices, threaded together as a monolith on your hostname along with things like Heroku, GitHub Pages, and Ghost Blogs? That's a good case for Fly.

If you're on a plan greater than Now's "free" plan, you can attach our open-source utility Wormhole to your deployments. Using Wormhole, you can achieve full end-to-end encryption - from client, to edge, to app, and back again. As your deployments grow in end-points, we load balance using the power of 2 random choices between those endpoints, ensuring sane and even traffic distribution across all available nodes.

Additionally, you'll receive access to an expansive library of Middleware. Inject Render Speed Tracking, A/B testing, Geo-IP Headers, unblockable server-side Google Analytics, myriad JavaScript-based snippets like Bugsnag and Olark, without altering any of your site code. You can keep your project folders and code clean, then use our network of edge proxies to cleanly cut-in features that might otherwise lead to bloated and messy code.

To connect a Now backend with Fly, here's what you'd do. We'll assume you have Now up and running. First, you'd configure an alias for your Now application. You'd want a relatively static URL when connecting to Fly.

now alias https://fly-prod-etjnigdrkz.now.sh fly-prod

We've now aliased our dynamic fly-prod-etjnigdrkz.now.sh hostnames to fly-prod.now.sh. As you add more backends, simply diversify the alias: fly-dev, fly-staging, name them whatever you'd like.

Head to Fly. If you don't have an account, you can sign up here. Create your first site, or choose to Add a backend to your existing site. Select now, then place in your now alias URI:

Add Now to Fly

Click Add backend. That's it! If you're using Now's free plan, you can use Fly to stay on that plan while using a custom hostname. If you're on a paid plan and want to attach Wormhole for added performance and security, check out our documentation.

You can now setup rules to route to your Now backend however you'd like. Thread as many backends together into one secure, SEO-plump hostname. Add custom Middleware. Ride a jalopy or eat a fish-stick. The world is in your hands. Fly is free to sign up, as are your first 2,000,000 requests and 100GB of transfer every month.

Kellen Evan Person

https://goodroot.ca

Kellen Evan Person

A polite, forest-dwelling Canadian who enjoys coding and writing. He's spent near two decades building web applications and strives to keep development fun and light-hearted.

North Vancouver, Canada