6
Best practices to optimize code and build robust and scalable web applications 1.1 Introduction This document discusses best practices and performance considerations for developing web Application applications. To begin, let’s have a look at the overall application development process and how performance engineering fits into the picture.

Best practices to optimize code and build robust and scalable web applications

Embed Size (px)

Citation preview

Page 1: Best practices to optimize code and build robust and scalable web applications

Best practices to optimize code and build robust and scalable web applications

1.1 Introduction

This document discusses best practices and performance considerations for developing web Application applications.

To begin, let’s have a look at the overall application development process and how performance engineering fits into the picture.

Page 2: Best practices to optimize code and build robust and scalable web applications

A basic development lifecycle with performance engineering integrated into the process is shown in Figure above. Note that this process itself is often performed in an iterative manner that includes both prototypes and multiple production releases.

The corrective measures after an unacceptable performance test get increasingly more expensive and detrimental as you are required to go farther back in the process. Thus, it is very important to spend some initial time considering performance during the establishment of the overall application architecture. It is much easier to refactor portions of the application code than it is to change the underlying application architecture. As was alluded to earlier, there should still be a balance in terms of how

Page 3: Best practices to optimize code and build robust and scalable web applications

Best practices to optimize code and build robust and scalable web applications

much time and effort is spent on this topic, but the following guidelines usually hold true:A scalable, efficient architecture is a must for high-performance applications.Lower-level optimizations can always be done later.

2. Source code management

In development, it is important to manage generations of code. Carefully organize and track application builds and the source code used to create them to avoid confusion. In addition to tracking the version of the source code, it is equally important to track the version of the build tools and which machine was used to generate a build. Not all problems are due to bugs in source code.Developers produce code and usually use an integrated development environment (IDE) such as the Application Server Toolkit or Rational Application Developer to do that. Code in an IDE is stored in a workspace on the file system, usually locally on each developer’s machine. As the project continues, and perhaps new members join the team, the code grows and it becomes necessary to manage the code in a central master repository. This allows for:_ Development team collaboration (work on common code)_ Code versioning (managing which versions are in which releases)_ Wider team collaboration (access for project managers, testers)

Scalability

Scalability is one of the most important factor in designing the web applications. When the number of messages exceeds a certain quota, storage service responds with an HTTP 503 Server Busy message. This message indicates that the platform is throttling the queue. Application designers should perform capacity planning to ensure that an appropriate number of queues can sustain the application’s request rate. If a single queue is unable to handle an application’s request rate, design a partitioned queue architecture with multiple queues to ensure scalability.

An application could also leverage several different queues for different message types. This ensures application scalability by allowing multiple queues to co-exist without choking a single queue. This also allows discrete control over queue processing based on the sensitivity and priority of the

Page 4: Best practices to optimize code and build robust and scalable web applications

messages that are stored in different queues. High priority queues could have more workers dedicated to them than low priority queues.

3. Application Architecture

Web application architecture is the approach used to design and plan your website. It is the way we organize content in our website. It consists of two basic components, technology decisions and structural decisions.

Best structural decisions for good website architecture

Avoid dynamic URLs. Yes, Google can index dynamic URLs pretty well nowadays, but for a normal user it is a pain in neck job

Avoid session IDs. If your CMS adds a session ID for each user at the end of the URL then you need to change that as soon as possible! Different URLs pointing to the same content means duplicate content. And we all know what that means.

Content/links in Java/JavaScript/Flash. It is always better to use plain and simple HTML. Some search engines find it difficult to read content in Flash or JavaScript. Let’s make their life easier.

302 redirections. Make sure all redirections are 301 and not 302. A 302 redirection may redirect the user to the new page but does not transfer any “link juice” from the old version of the page to the new one. 301 redirection should be your default type of redirection if SEO matters to you.

Website hierarchy should match the way users search. Start with your home page, and work your way to all the internal pages as you want to make sure that the flow of navigation makes sense and is easy to follow. Create categories and subcategories if necessary. You can use a “card sorting” technique to create your category tree.

Cross-link relevant content. This way you “cluster” all relevant content, you pass “link juice” to all thematically relevant pages and make your user happy, as he may find easily whatever he has been looking for during his visit in your website.

Use proper anchor text. Internal linking is pretty powerful, especially if your website has thousands of pages. Take advantage of it and use targeted keywords as anchor text instead of “more”, “click here” and other generic terms. Prepare yourself to train designers as well. Yes, they will be the first to complain.

Use breadcrumb navigation. It very convenient when I user can navigate a site via its breadcrumbs instead of clicking sidebar menus

Page 5: Best practices to optimize code and build robust and scalable web applications

Best practices to optimize code and build robust and scalable web applications

or large navigation menus. This is where the “use proper anchor text” tip can be applied to. Extra PRO tip: Use proper format to produce rich snippets which affect CTR.

Minimize link depth. Rule of thumb: No page should be deeper than 3 clicks away from your homepage. Make you site architecture flat. The deeper you “bury” a page, the less “link juice” is passed, the less “link juice passed” to a given page, the more difficult will be for a page to be kept in Google index. As we know, if a page has an amount of “link juice” which is below a certain threshold, then Google is very likely to drop this page from its index (or not index it at all).

Conclusion

Making an application robust, is an ongoing process. You discover bugs, fix them, and write tests to make sure they don't come back. When your application goes down due to an external system failure, you isolate that system to make sure the failure can't snowball again. Exception handling is your best friend when it comes to doing this. Even the most failure-prone application can be turned into a robust one if you apply good exception handling practices consistently, over time.

Of course, exception handling is not the only tool in your arsenal when it comes to making applications more resilient. Also, Asynchronous processing, can be applied to make application fault tolerant.