Moving Complex Enterprise Ecommerce Systems to the Cloud
Eddie ChanRonald Chen
Elastic Path™
Elastic Path Software
• We help the worldʼs biggest brands sell digital goods and services
• We provide a flexible Java ecommerce platform and expertise in ecommerce strategy and implementation
• #1 ecommerce blog: www.getelastic.com• For more on-demand ecommerce resources:
www.elasticpath.com/resources
Elastic Path Architecture Components
Mobile BrowserWeb Browser Commerce Manager Client
Eclipse RCP SWT / JFace
Financials ERPSystem
CMSSystem
LegacySystems
Custom /LOB Apps
PaymentGateway
Database Server
Store Front Server
Spring Security
Core Engine
Drools
Spring MVC
Apache Velocity
Commerce Manager
Spring Security
Core Engine
Quartz Scheduling
Spring Remoting
Web Services Server
Spring Security
Core Engine
JAX-WS
SOLR Search Server Core Engine
Search Server
Quartz Scheduling
ETL Tools
XML Import/Export
Core Engine
Data Sync Tool
Core Engine
J2EE Application Server
The Elastic Path Platform
Ecommerce is complex.Enterprise ecommerce is complex-er.
Case Study
• Since 2008, Elastic Path has been the ecommerce backbone of a few of Googleʼs online stores
• For these stores, many customizations have been made to the Elastic Path platform.
• One of the largest customizations thatʼs been made to the Elastic Path platform is migrating it to run on Google App Engine.
Migration to Google App Engine
• EP running in the Colo• Fixed Cluster
Before: After:
• EP running on App Engine• Dynamic instances
Google App Engine
• Same system that powers many of Googleʼs own apps• GAE is a Platform as a Service (PaaS)• More restrictive than Infrastructure as a Service (IaaS)
offerings (but for good reasons)• Supports Python, Go, and Java (& other JVM
languages)• Free to get started; pay as you go pricing
Advantages of Google App Engine
• Automatic Scalability• Well defined development environment• Secure• Easier deployments and operations• Reduced Cost• Built-in monitoring tools• Useful services
Topics
• Challenges with Restricted Classes• How App Engine Automatically Scales• Performance, Performance, Performance• Migrating the Persistence Layer
Topics
• Challenges with Restricted Classes• How App Engine Automatically Scales• Performance, Performance, Performance• Migrating the Persistence Layer
Challenges with Restricted Classes
• App Engineʼs JRE Class White List:
The full list of white list classes can be found at:http://code.google.com/appengine/docs/java/jrewhitelist.html
These JRE Classes work on App Engine. All other JRE Classes do not.
File Restrictions
• Not allowed:• Reading/writing to the filesystem
(this should not be done anyway)• Writing to files inside the WAR• Allowed:• Reading from files inside the WAR
Example: File Restrictions
• Problem: we were reading/writing to the filesystem• Solution: we moved the read-only files into the WAR
and moved the read/write data to the Datastore
Before: After:
Socket Restrictions
• App Engine does not allow the use of raw sockets• Reason: security considerations• Workarounds may exist depending on the nature of
the communication• e.g. HTTP sockets & App Engine URL Fetch Service
Example: Socket Restrictions
Before: After:
• Problem: We used HttpClient, which uses sockets, for Spring HTTP Remoting
• Solution: There is a custom connection manager for HttpClient 4 that uses App Engine URL Fetch Service instead of sockets
Thread Restrictions
• App Engine does not allow spawning of threads• Use Task Queues instead of threads for background
jobs• Task Queues:• Like a Java Executor• Highly configurable• Accepts URLs instead of Runnables• Code that would have been in Runnable is bound to
a URL• Fetching the URL is like running the task on another
thread
Example: Thread Restrictions
Before: After:
• Problem: Generating a file on a background thread• Solution: Migrate Runnable to Spring Controller and
schedule with App Engine Task Queues instead of Executor
Topics
• Challenges with Restricted Classes• How App Engine Automatically Scales• Performance, Performance, Performance• Migrating the Persistence Layer
How App Engine Automatically Scales
“App Engine apps are powered by any number of dynamic instances at any given time, depending on the volume of requests received by your application. As requests for your application increase, so do the number of dynamic instances powering it.”
http://code.google.com/appengine/docs/adminconsole/instances.html
Requests Instances Requests Instances
How App Engine Automatically Scales
• A single instance handling requests• This instance, like all instances, has a request queue to
hold incoming requests
How App Engine Automatically Scales
• A new request comes in• Instance-1ʼs request queue is getting overloaded, so...
How App Engine Automatically Scales
• App Engine spawns a new instance to handle request-5• request-5 is a loading request; request-5 must wait for
instance-2 to fully initialize before being processed
How App Engine Automatically Scales
• instance-2 finally finishes initializing and can now handle requests alongside instance-1
How App Engine Automatically Scales
Loading requests make users wait!
Introducing warm-up requests:• Introduced in Google App Engine v1.4.0• Initialize instances ahead of time so that live requests
do not initiate new instances• On by default• Not always called for every new instance (e.g. the very
1st instance)
How App Engine Automatically Scales
Letʼs replay the previous scenario with warm-up requests. • A single instance handling requests• App Engine sees that instance-1ʼs request queue is
getting overloaded, so...
How App Engine Automatically Scales
• Before any more requests arrive, App Engine sends a warm-up request to initialize a new instance
How App Engine Automatically Scales
• instance-2 finishes initializing and is ready to handle requests alongside instance-1
How App Engine Automatically Scales
• A new requests comes in• instance-2 is ready to handle request-5 right away• request-5 is not a loading request this time
How App Engine Automatically Scales
Fast-forward a few seconds. request-1, 2, and 5 have been processed. • instance-2 is idle and instance-1ʼs queue is not full, so...
How App Engine Automatically Scales
• App Engine scales down and drops instance-2 because it is no longer needed
How App Engine Automatically Scales
Introducing Always-On Instances:• Always-On instances remain running even with no traffic • Minimizes impact of loading requests• A premium feature (i.e. costs a bit more)
Topics
• Challenges with Restricted Classes• How App Engine Automatically Scales• Performance, Performance, Performance• Migrating the Persistence Layer
Performance Tools - AppStats
• AppStats• A servlet filter that measures the performance of each
request
Performance - Loading Deadline
• Recall that any request has the potential to be a loading request
Performance - Request Deadline
• Still need to handle actual request in the remaining time after loading application
• After 60 seconds, a runtime exception will be thrown and the requests will be dropped
Performance - Optimizing
• Loading Request time = Start-Up time + Request time• To thrive on App Engine, request performance and start-
up performance must be optimized together
OptimizeStart-Up
OptimizeRequests
Performance - Optimizing Start-Up
How do you optimize start-up times?
Performance - Optimizing Start-Up
How do you optimize start-up times?
Do Less
Performance - Optimizing Start-Up
Do less at start-up:• In our application half the start up time was being
consumed with classloading• Amount of classloading is application/framework specific• We were loading more classes than expected• Use -verbose:class• Classpath scanning is slow• Use static configuration instead of classpath scanning• Generate configuration at build
Performance - Optimizing Page Loads
• Serve resources from the WAR statically
Before: After:
Performance - Optimizing Page Loads
• App Engine provides memcache service• Cache is shared across instances
• Best effort cache• In our application we gained performance by caching
Spring Remote calls
Topics
• Challenges with Restricted Classes• How App Engine Automatically Scales• Performance, Performance, Performance• Migrating the Persistence Layer
Migrating the Persistence Layer
• Google App Engineʼs persistence layer is Datastore• Datastore is a non-relational database• Most enterprise applications use a relational database• Non-relational databases donʼt have tables
SQL Table: Datastore (abstract):
Migrating the Persistence Layer
• Transaction boundary in Datastore is very different• Can only perform transaction around entity groups• Each entity has a parent entity• An entity group is a tree of entities
Migrating the Persistence Layer
• Existing domain model unlikely to work in Datastore• Different storage structure• Different transaction model• Different tools/framework
What do we do?
Migrating the Persistence Layer
• Existing domain model unlikely to work in Datastore• Different storage structure• Different transaction model• Different tools/framework
What do we do?
Run Away?
Migrating the Persistence Layer
• Datastore is designed to scale with the App Engine cloud• Entities are far easier to cache• Fetches are small and focused• No more fetch group hell• The data and transaction model force cleaner domain
models• More flexible than tables• Can have different properties on the same “type” of
entities• Focus on smaller transactions• Alternatively, use Google Cloud SQL
Letʼs Recap
• Elastic Path is a flexible Java ecommerce platform• Google App Engine is a true cloud platform that
supports Java web applications• App Engineʼs constraints can be liberating• JRE Class restrictions forced one to implement
workarounds with App Engine services• Automatic scalability is achieved with dynamic
instances• App Engine imposes strict performance requirements
on your apps• The Datastore is a non-relational DB that forces one to
untangle the domain model
Was the Migration Worth It?
Was the Migration Worth It?
For us, yes!
Was the Migration Worth It? - Yes!
• Automatic scalability• App Engineʼs restrictions forced us to rethink and
improve our applicationʼs design• Deployments to App Engine are flexible and easy• Production environments are easy to replicate for
testing• No more server configuration management• Reduced costs• Frequent Google App Engine releases continue to
introduce cool, useful features
For more information visit:Web www.elasticpath.comBlog www.getelastic.comTwitter @elasticpath
Thank you.Any Questions?
Additional Resources• Google App Engine homepage: http://code.google.com/appengine/• Maven plugin for Google App Engine: http://code.google.com/p/maven-gae-plugin/• Will It Play In App Engine - lists the level of compatibility of various Java technologies and
App Engine: http://code.google.com/p/googleappengine/wiki/WillItPlayInJava• ESXX - Custom HttpClient 4 URLFetch connection manager: http://esxx.blogspot.com/
2009/06/using-apaches-httpclient-on-google-app.html