Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Heroku Cloud Application Development
Heroku Cloud Application Development

Heroku Cloud Application Development: A comprehensive guide to help you build, deploy, and troubleshoot cloud applications seamlessly using Heroku.

eBook
$33.29 $36.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Heroku Cloud Application Development

Chapter 2. Inside Heroku

Now that we have test driven Heroku and know a little bit about its feature set, it's time to understand some inner workings of the Heroku platform.

The Heroku cloud development platform provides you with the foundation for developing, deploying, and troubleshooting your cloud-based applications. It is comprised of the following components:

  • The platform stack: This provides core components such as the operating system, language runtime, and supporting libraries.

  • Request routing mechanism: This provides support to accept client requests and route them reliably to the running process.

  • The execution environment: This provides the necessary runtime support to run your apps.

  • The Logplex logging framework: This is an event logging system to collate application events that emanate from different processes for further processing.

  • The add-on ecosystem: This provides the ability to easily plug in third-party libraries to provide value added services, such as performance monitoring...

The Heroku platform stack


Heroku is a platform, that is, an environment that provides you with the foundation to run your applications without worrying about the nitty-gritty of how it all works under the hood. You build an application, push it to Heroku, and voila, the slug compiler builds your source into an executable and ready-to-run application. What's more, it also creates a URL for the application to use. While all this magic works for you in no time, there is a robust, highly available, scalable, and failure-proof foundation underneath that makes all this possible. The core element of the Heroku platform is the Heroku stack—a combination of the operating system, language runtime, and associated libraries that provide a complete execution environment for users to run applications of varying workloads and scale seamlessly.

In the deployment stack, the operating system defines the base technology used by the Heroku platform, and it has varied across various releases of the Heroku stack...

Request routing in Heroku


In the current deployment stack, an app named myapp will have the default hostname of myapp.herokuapp.com. The herokuapp.com domain routes any request to Heroku via the routing mesh and provides a direct routing path to the corresponding web processes. This allows for advanced HTTP uses such as chunked responses, long polling, and using an asynchronous web server to handle multiple responses from a single web process.

The routing mesh is responsible for directing a request to the respective dyno in the dyno manifold. The routing mesh uses a round robin algorithm to perform the distribution of requests to the dynos as shown in the following diagram:

The HTTP request follows a timeout (30 sec) for the web process to return its response data to the client. If the web process fails to return the response within this time, the corresponding process log registers an error. After the initial communication, a larger (55 sec) time window is set for client or the server to...

Heroku's logging infrastructure – the Logplex system


The Logplex system forms the foundation of the Heroku logging infrastructure. It collates and distributes log messages from the application and other parts of the Heroku infrastructure. These entries are made available through a public API and the Heroku command-line tool. Due to the distributed nature of the Heroku platform, trying to manually access log messages across different application components and making sense out of those is practically infeasible. You cannot get a unified view of the entire system behavior if you collate these messages manually and try to troubleshoot problems. The Logplex integrated logging system provides an alternative in this case.

The Logplex system acts like a conduit that routes messages from log entry sources, that is, the producer of the log messages (for example, an application running on the dyno, the Heroku platform itself) to log entry drains, that is, consumers of log messages (for example, archival...

The Heroku add-on architecture


Add-ons are one way to extend the capabilities of a Heroku application. The user can add a new service such as caching or data storage to the app by provisioning an add-on and consuming the service offered. Heroku users have two ways to provision the add-ons:

  • The add-on marketplace

  • The Heroku toolbelt client

The entire process of add-on provisioning and consumption is shown in the following diagram:

The following steps describe how a new add-on is provisioned and consumed by the Heroku app:

  1. The Heroku user requests an add-on using either of the two ways indicated in the previous paragraph.

  2. Heroku sends a provisioning request for the current account to the service provider for the given service.

  3. The service provider validates the request and creates a private resource for the caller and returns a URL that specifies the exact location and the credential required to access the service.

    For example, the Amazon RDS service provider might return:

    MYSQL_URL=mysql://user:pass...

Programmatically consuming Heroku services


With Heroku Platform API, Heroku provides you with the ability to call the Heroku platform services to do virtually anything you need to do on Heroku—creating an application, checking the release history of your app, or plugging new add-ons in to your application. All this and more just by using simple HTTP. The following diagram depicts the interaction between a simple Heroku API client and the Heroku platform services. An API client can use the Heroku API to interact the core platform services of Heroku using a well-defined interface.

The Heroku Platform API allows you to do almost everything you can do with the Heroku command line or dashboard. This API is a powerful tool for application developers to leverage the capabilities of Heroku's features and gain complete control of their apps, from creating to monitoring them.

The Heroku Platform API

There are at least three important components of the Heroku Platform API as shown in the following diagram...

The Heroku process architecture


A Heroku application is a collection of processes that run on the Heroku dyno manifold. Whether you are running a local process or a remote one on a distributed cluster of machines, a Heroku application is essentially a set of processes, each consuming resources like a normal UNIX process.

To add flexibility and have better control over how you define your process configuration, Heroku defines the concept of process type. Each process that you run as a dyno can be classified as a web process or a worker process type depending on whether it handles HTTP requests or does some background processing. You could also define a custom process type to add flexibility to your application definition.

Procfile

Heroku has a language agnostic, application centric method of defining your process types through a configuration file called Procfile—a format for declaring the process types that describe how your app will run.

Procfile is a text file named Procfile placed in the...

Running applications locally


How often have we faced issues in the production environment that fail to reproduce in the development environment? Hence, it is critical that when developing and debugging an application, the code in a local development environment is executed in the same manner as the remote environment. This ensures that any differences between the two environments and bugs that hard to find are intercepted before deploying the code to production.

In a local development environment, you can run a small-scale version of your application by launching one process for each of the two process types: web and worker.

Foreman is a command-line tool used to run Procfile-based applications locally. It is installed automatically by the Heroku toolbelt (Heroku client package), and is also available as a gem.

If you don't have foreman installed, use the gem install foreman command to install it from the prompt.

Starting foreman is easy as shown in the following screenshot:

Since the Procfile...

Setting local environment variables


Variables saved in the .env file of a project directory will be added to the environment when run by foreman.

For example, we can set SRCPATH_ENV to development in your environment, as shown in the following screenshot:

The command in the preceding screenshot runs the interactive shell and sets the value of the SRCPATH_ENV environment variable to SMS.

You can use the .env file for the local configuration as it has settings specific to your local environment. It does not need to be checked in or committed to Heroku.

Process formation


Each application's set of running processes on the dyno manifold are known as its process formation.

The default formation for a simple application will be a single web process, whereas more complex applications may consist of multiple copies of web and worker process types. You can scale the process types on demand as your application needs increase.

For example, if the application already has a process formation of three web processes, and you run the heroku ps:scale worker=3 command, you will now have a total of six processes: three web processes and three worker processes.

Process scaling

In a production environment, your application may need to scale out to a much greater capacity. It is no longer a couple of web and worker processes that you typically need for your application deployed in the local environment.

Heroku follows a share-nothing process architecture. This enables the instantiation of each process type a number of times. Each process of the same process type...

Running a one-off process


Heroku's process architecture enables you to run a group of processes (process formation) or a standalone one-off process. On your local machine, you can cd into a directory with your app, then type a command to run a process. On Heroku's Cedar stack, you can use heroku run to launch a process against your deployed app's code on Heroku's dyno manifold.

To run the date command on Heroku as a standalone dyno, type the code as shown in the following screenshot:

The command displays the date on the terminal by running a standalone dyno with process ID 2963. Each of these commands is run on a fresh, stand-alone dyno running in different physical locations. Each dyno is fully isolated, starts up with a clean copy of the application's ephemeral filesystem, and the entire dyno (including the process, memory, and filesystem) is discarded when the process launched by the command exits or is terminated.

Running anything


You can pretty much run anything on the Heroku platform. If you need additional features for your web app, you can use the supported add-ons and consume the add-on services from your app and provide newer capabilities such as monitoring (of the app) or data storage in your application. The possibilities are endless.

Let's say you want to swap the web server and worker system used for your Rails application and use Unicorn and Resque respectively instead.

You just need to change the Gemfile and Procfile, and that's it. You are ready to go!

The Gemfile changes are as follows:

gem 'unicorn'
gem 'resque'
gem 'resque-scheduler'

The Procfile changes are as follows:

web:     bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker:  bundle exec rake resque:work QUEUE=*
urgworker: bundle exec rake resque:work QUEUE=urgent

The urgworker is a new custom process type defined to signify tasks with an urgent QUEUE type. You get the flexibility of scaling these process types independent...

Summary


In this chapter, we delved deeper into the various components that form the Heroku platform. We understood the foundation of the Heroku platform, its stack, and how the currently supported Celadon Cedar provides different capabilities that help build and scale web apps seamlessly. We also looked at how user requests gets routed and finally executed in the Heroku execution environment. We briefly covered Heroku's Logplex logging infrastructure that helps trace the internal proceedings of your web app. We also looked at Heroku's add-on architecture that helps developers extend the Heroku platform and build newer capabilities for their apps. We learned how to programmatically execute Heroku operations by leveraging the Heroku Platform API and finally we reviewed the process architecture of Heroku—the single most important subsystem of the Heroku platform.

Now that we have the required foundational understanding of the Heroku platform, we will start learning how to build real, robust...

Left arrow icon Right arrow icon

What you will learn

  • Recognize the components of the Heroku infrastructure and how they work together to give a seamless platform experience
  • Write an application using any supported language (Ruby, Java, PHP, Python, and more) and deploy it easily and instantly
  • Run and scale your cloud application on demand using a variety of useful Heroku commands
  • Secure and debug your cloud application faster using popular techniques and tools
  • Reuse the provided samples to build agile and robust applications
  • Extend your application features by using simple plugins and addons
  • Manage all your applications intuitively using the onestop Heroku dashboard
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 24, 2014
Length: 336 pages
Edition :
Language : English
ISBN-13 : 9781783550975

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Apr 24, 2014
Length: 336 pages
Edition :
Language : English
ISBN-13 : 9781783550975

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 170.97
Heroku Cookbook
$54.99
Heroku Cloud Application Development
$60.99
Node Cookbook: Second Edition
$54.99
Total $ 170.97 Stars icon

Table of Contents

10 Chapters
Hello Heroku Chevron down icon Chevron up icon
Inside Heroku Chevron down icon Chevron up icon
Building Heroku Applications Chevron down icon Chevron up icon
Deploying Heroku Applications Chevron down icon Chevron up icon
Running Heroku Applications Chevron down icon Chevron up icon
Putting It All Together Chevron down icon Chevron up icon
Heroku Best Practices Chevron down icon Chevron up icon
Heroku Security Chevron down icon Chevron up icon
Troubleshooting Heroku Applications Chevron down icon Chevron up icon
Advanced Heroku Usage Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Sarah Khalid Jun 05, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book for developers who want to get started with using the Heroku platform.It provides step by step instructions with diagrams and screenshots to help you.Will definitely recommend!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon