Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Introduction

Introduction

A single hype is not enough to change the world. But multiple hypes together can change it as long as they are part of a bigger trend.

This book discusses more than one hyped technology: cloud computing, NoSQL, and HTML5. The technologies in this book combine well with other hyped technologies: functional languages (Scala) and connected devices (iPhone, iPad, Android).

The Internet is changing the world. That is old news, yes, but because it’s old news, you may easily overlook the Internet’s ongoing dynamics and influences. A good indicator that you are missing the cybership is if you are still stuck on Spring and Hibernate. Frameworks solving yesterday’s problems are blocking the way to handle tomorrow’s challenges.

The Google App Engine is a perfect fit with current Internet trends. Reading this book gives you a head start with upcoming technologies. This Introduction describes how both the App Engine and this book fit in the current trends.

Analyzing Internet Trends

To analyze the current Internet trends, you need to take a few steps back in time and see what has happened in the past two decades.

Starting in the Nineties

Let’s start with the early 1990s. At first, the World Wide Web was used mostly to serve static HTML pages. The best way to serve a dynamic web application was to configure a /cgibin directory connecting to Perl scripts or binary programs that redirected the output to the web visitor. Web applications were nowhere near as mature as classic office applications. By the late nineties, though, developers were incorporating best practices from classic office automation into web applications, and the Internet soared with the dot-com bubble.

Switching to the New Millennium

In the early 2000s, web programmers realized that a Model-View-Controller pattern was not such a bad idea after all. And around 2005, Asynchronous JavaScript and XML (AJAX) helped make web applications more interactive. By 2008, web applications and office applications were on the same maturity level, sharing many of the same technologies, such as SQL databases and heavy application servers. Some UI libraries even tried to mimic classic Windows interfaces, with the ultimate goal of bringing a not-so-user-friendly interface concept into the browser.

Analyzing Current Developments

Right now, you can see the start of a trend in which Internet technology surpasses the maturity level of classic office automation. The frontrunners in Internet technology are critically investigating all parts of their systems and analyzing their designs for fit with the requirements of the current Internet environment. New technologies are being developed from scratch with the Internet’s scalability requirements as a first priority.

It won’t be long until office automation will have trouble keeping up with Internet technologies. That is the point where office automation will start adopting the best practices from the Internet instead of the other way around.

Replacing SQL Databases with NoSQL

Relational databases are one of the most widely used technologies in classic office automation. They are mature, well standardized, taught in most schools and universities, and available in all sizes. However, they were designed at a time when storage was still expensive, the number of users was limited to the number of employees in a single company, and the focus of their use was on transaction processing.

Relational databases do not scale well. They were designed as central storages operating efficiently enough to handle most of their work alone. In larger environments, their capabilities can be expanded using horizontally or vertically distributed databases or load-balanced setups that replicate data among multiple machines. Usually this functionality requires expensive software, machinery, and specialized knowledge, though, so at the end of the day, relational databases are still limited.

Switching to NoSQL with the Google App Engine Datastore

A common characteristic of NoSQL databases is high scalability. NoSQL databases are designed specifically with the requirements of the Internet in mind. To serve millions of visitors around the world in a few hundred milliseconds, you need functionality beyond that of relational databases. If you do not need to serve that many visitors, you may still consider relational databases because of their consistency and transactional integrity. You should choose NoSQL only if the advantages match your requirements.

Google App Engine offers the datastore as NoSQL storage. It allows you to store entities, each with a set of key-value pairs. A value can also consist of an array of values. Benefits of the App Engine offering are that you need not worry about system administration, and its APIs easily integrate with the rest of the platform.

When you start working with the App Engine datastore, you discover that NoSQL databases have additional advantages over the classic SQL offerings. The APIs are less awkward to use than JDBC APIs.

Moving Away from Object Relational Mapping

Object relational mapping has always been painful. Doing the mapping yourself is so cumbersome that it scares developers into using heavy and code-intensive frameworks like Hibernate, Java Data Objects (JDO), and the Java Persistence API (JPA). Choosing not to map relational structures to objects is virtually impossible. It would imply keeping JDBC connections open longer than necessary.

NoSQL databases relieve you from the burden of object relational mapping. If you insist, you can still map your datastore’s structures to Java objects. This does not always make sense though. This book shows many examples of datastore entities being directly passed to an HTML template. The result is clean, simple, and efficient code.

Considering Alternative NoSQL Solutions

Examples of other NoSQL databases are Amazon SimpleDB, Riak, Voldemort, Microsoft Trinity, Hadoop, Cassandra, CouchDB, MongoDB, Kyoto Cabinet, Hypertable, GraphDB, Redis, Google Pregel, and Google BigTable (the underlying platform of the App Engine’s datastore). Each of these products has its own characteristics. Some are key-value storages, graph storages, document storages, or variants of these structures.

After reading this book and practicing with App Engine datastore, you should investigate the various NoSQL initiatives for your work on platforms other than the App Engine. Many of the advantages of the datastore on the App Engine platform can also be found outside the App Engine. This is all part of a larger trend, after all.

Computing in the Cloud

Cloud computing changes the way you write your applications. Classic enterprise applications usually optimize performance by taking a performance hit at startup time. If your application is restarted only once every few months, that can be an acceptable strategy. However, on some cloud platforms, including Google App Engine, your applications may be started and stopped multiple times an hour. This means that you should optimize your application to start up extremely fast, which may require throwing out all heavyweight frameworks, like Spring or Grails.

Maintaining Systems in the Cloud

Hosting applications in the cloud means hosting without worrying about the underlying infrastructure. In all cloud offerings, you pay only for what you use. This is especially interesting if your site experiences sudden high spikes in visitors. In classic setups, you require a machine park that is standing still most of the time, waiting for the exceptional spike when it really needs to work.

The advantage of the App Engine over other cloud initiatives is that it scales automatically. You need not give orders to start up additional instances of your application. If you are worried about controlling your budget, you can set a maximum on your every day expenses. This helps you prevent bankruptcy after a distributed denial-of-service (DDOS) attack.

The App Engine does not expose details of the underlying operating system to its users. Cloud services like Amazon Elastic Compute Cloud (EC2) and Microsoft Azure let users maintain their own instance of an operating system. This is a trade-off between freedom and maintenance costs.

The App Engine could be characterized as a software developer’s cloud platform, whereas EC2 could be characterized as a system administrator’s cloud platform. Microsoft Azure is most interesting if your company is already running on a full Microsoft stack. It fits best with the .Net developer community, although it must be mentioned that Microsoft also targets Java developers with its Azure platform.

Make an informed decision about which platform you’ll use before you start developing, because some lock-in is involved. Don’t choose the App Engine just because it’s Google or because you liked the cover of this book. Choose it because you want a well-integrated platform that relieves you from the burden of system administration and automatically scales to sudden changes in demand even while you sleep.

Connecting with Other Cloud Offerings

You can also consider cloud computing from a nontechnical perspective. When managers discuss cloud computing, they are usually talking about Google Apps rather than Google App Engine. Google Apps includes Google Docs, Gmail, Google Calendar, and Google Sites for Business. The App Engine is just a technical platform on which software vendors can host their applications. Managers may not be interested in such hosting. They are interested in the applications.

The Google Apps Marketplace helps software vendors sell applications that integrate well with Google Apps. The Google App Engine is the ideal platform for hosting applications that integrate with Google Apps. Hosting in Google’s cloud may also help when selling your application to customers who already use Google Apps.

Adopting HTML5

HTML4 and XHTML1 have ruled the world for a long time. Now it is time to move on. The World Wide Web made a shift from serving documents to serving web applications. And even though documents will probably be served until the end of time, the real technical challenge is in serving user-friendly web applications.

Web interfaces are more easily understood by the average user than classic Windows interfaces. In operating systems, you can see a trend toward simplifying client-side interfaces to work similarly to web interfaces. Smart phones show similar advancements. Smart phone vendors are trying to keep up with the simplicity of Apple’s iPhone.

HTML4 and XHTML1 have some limitations that quickly become awkward when using them to offer web applications. A lack of descriptive HTML element names is just a minor flaw that leads to overly complicated Cascading Style Sheet (CSS) files. HTML5 fixes this problem. More interesting are the additional JavaScript APIs offered with the HTML5 specification.

Using HTML5 offers many benefits. For example, consider the File Chooser dialog when uploading a file. HTML5 allows you to drag and drop files into your browser. You can try this by adding an attachment in Gmail using drag and drop. Another example is the use of cookies or heavy server-side sessions. HTML5 offers session storage, local storage, and IndexedDB to store about 5MB of data on the client for later reuse. HTML5 allows you to make drawings on the client side using the Canvas.

Finally, the support for HTML5 on mobile and connected devices is better than you might expect. Some of the features of HTML5 are particularly useful on handheld devices. The lack of Flash support on iPhone and iPad is well compensated by HTML5. And possibly one of the most interesting features of HTML5 on a mobile device is the ability to ask for the user’s location. If the user allows it, you can use it to customize search results to the things most relevant in that particular area.

Discussing Trends Out of Scope for This Book

Essential App Engine: Building High-Performance Java Apps with Google App Engine discusses some of the latest trends in cloud computing with NoSQL and HTML5. Some related trends are beyond the scope of this book, but with some additional reading, you can combine these trends with the technologies discussed here.

Serving Apps on Connected Devices

The examples in this book assume that the visitors are accessing the application using a web browser or a mobile browser. All examples target HTML, CSS, and JavaScript.

In addition to browsers, applications are increasingly served through platform-specific applications running on the iPhone, iPad, Android, Windows Phone, or BlackBerry. Numerous books on developing applications for these platforms are available.

From an App Engine perspective, requests from mobile applications are in many ways similar to AJAX requests made from browsers. You can serve JSON (JavaScript Object Notation) strings over a RESTful interface, providing the same data in a format that is easily read by the applications.

Moving to New JVM Languages

Java has been called the Cobol of the 21st century. Without arguing against that, the examples in this book are nevertheless in Java. A seeming trend away from the Java language does not necessarily imply moving away from the Java Virtual Machine (JVM). Most popular new languages like Scala and Clojure compile to JVM bytecode.

At this point, the Java language is still the largest language on the JVM platform. Despite its growing popularity, Scala has nowhere near the user base of Java yet. And even for those who are interested in other JVM languages, the Java language itself serves well as the lingua franca of JVM languages. This book demonstrates the Google App Engine API in a language-neutral way, independent of the heavy Java framework. Code examples in this book easily translate to Scala, Clojure, Groovy, JRuby, or Jython.

This Book’s Target Audience

Essential App Engine is written for software developers and software architects.

For software developers, this book provides a hands-on approach to developing applications for the Google App Engine. It contains many simple, standalone code examples that demonstrate the concepts without distractions of unrelated code and frameworks. Software developers can modify the examples to use as working code, realizing their applications.

Software architects can read this book to get a general overview of the characteristics of the App Engine platform. In addition to the code examples, this book provides in-depth background knowledge of how the App Engine datastore differs from classic relational databases. It covers how you should change your design to get the best performance out of it. In addition, this book provides many pointers on how to change the way you design web applications to optimize their performance when hosted in the cloud.

Overview of This Book

This book contains twenty chapters divided into five parts. The order of the parts is consistent with a software development project that follows a design-first approach. You can read the chapters in a different order, though: Chapters are cross-referenced when more detailed background knowledge is desirable.

  • Part I, “An App Engine Overview,” introduces you to the basics of the App Engine. It presents a discussion of performance characteristics and a practical guide to setting up your development environment so that you can continually address performance.

  • Part II, “Application Design Essentials,” discusses all configuration options in the App Engine platform. It provides a design philosophy for modeling your data, targeting the Google App Engine datastore. And it discusses general technical design choices you should make before you start developing for the App Engine, such as whether or not to use Java Server Pages.

  • Part III, “User Interface Design Essentials,” focuses on modern browser technology rather than on the App Engine itself. HTML5 and CSS3 are great companions when developing web applications in the cloud. The added possibilities in the browser help relieve the server from a lot of work and memory usage, ultimately lowering your usage costs while leveraging a responsive and user-friendly application to your client. In addition to discussion of HTML5 and CSS3, Part III provides an elaborate explanation of how to use JavaScript and AJAX to continue programming on the client side.

  • Part IV, “Using Common App Engine APIs,” contains everything you need to know about the App Engine APIs. This includes the datastore, the Blobstore, the Mail API, task scheduling, memory cache, URL retrieval, web application security, and XMPP messaging.

  • Part V, “Application Deployment,” discusses how to improve your development process, optimize the quality of your web application, and sell it to potential customers.

The Essential App Engine Blog

Google provides frequent updates to the App Engine, adding new features and APIs, in response to popular demand. To keep you up to date, a companion website to this book, the Essential App Engine blog, is available at www.essentialappengine.com.

Check this website for the latest updates, the source code for this book, and additional code examples!