Home / Articles / Adobe ColdFusion / Scaling with ColdFusion MX

Scaling with ColdFusion MX

Chapter Description

This sample chapter will concentrate on what you need to know about scaling with Cold-Fusion MX: scaling considerations, writing ColdFusion MX applications that will scale, keeping server data in sync, the differences between hardware and software load-balancing options, scaling with ClusterCATS, and scaling with hardware-based load-balancing devices.

How to Write ColdFusion MX Applications that Scale

Pay special attention to scaling issues when you are writing applications for a clustered environment. Poorly written code can suffocate any Web site, no matter how much hardware you throw at it. Building applications that scale follows good coding techniques concentrating on writing clean, well-thought-out code. Scalable code is well-organized, modular in nature, structured, and avoids common bottlenecks.

Code Organization

A stable and scalable Web site typically contains well-organized code. This code is commented and easy to follow. All images are located in their own directories and not intermixed in with CFML and HTML templates. Subdirectories exist for partitioning the application into manageable units. This organization structure can be used to place different applications, all self contained in individual directories, on different servers for distributed scaling. Good-quality code organization and application partitioning eases deployment to multiple servers and reduces maintenance time. Bottlenecks are more easily definable and maintain existing code is easier, allowing for a more stable and error free Web site. Limiting the number of templates in any directory encourages good code organization on your site, which can lead to a more scalable site.

All Web pages for an application should follow a defined coding style and conformity needs to be enforced. Implementing coding styles and standards eases application maintenance. Understanding the functionality of an existing template that looks similar to other templates in style is easier. Well-documented templates tell the developer what functions the template is supposed to perform. Not following a coding style encourages random coding habits that are hard for other developers to understand and to maintain. In turn, applications that do not follow a coding style are harder to test for quality assurance and eventually crumble under their own unmanageable weight.


Modular code helps promote code re-use. Code that is used many times in an application, either in a custom tag or inline, might become more stable over time as developers fix bugs and tweak it for performance. The code will have undergone quality assurance testing multiple times and endured many load tests, therefore proving its durability. Well-written modular code follows good coding practices and avoids common bottlenecks. It also eases development efforts because developers do not have to rewrite this code every time they need similar functionality.

Streamlined, Efficient Code

Implementing best practices for Web site development is an important discipline for developers building highly scalable applications. The code in this example illustrates that point. The code attempts to find the name of the first administrator user. Each administrator user has a security level of 1. It queries all users and loops through the record set searching for the first administrator record and returns their names:

<cfquery name="getAdminUser" datasource="db_Utility">
         SELECT * FROM tbl_User

<!--- Loop until you find first user with security level of 1 --->
<cfloop query="getAdminUser">
        <cfif trim(getAdminUser.int_Security) IS 1>
                <cfset AdminName = getAdminUser.vc_name>

Admin User Name: <cfoutput>#AdminName#</cfoutput>

The example shows inefficient code that can slow your Web site if this piece of code sustains many hits. In addition, even after it finds the first administrator record, it does not stop looping through the returned user record set. What if the user table contained thousands of records? This code would take a long time to process and consume valuable system resources.

Here's an example of more efficient code for finding the first administrator record and returning the name:

<cfquery name="getAdminUser" datasource="db_Utility">
          SELECT TOP 1 vc_name FROM tbl_User WHERE int_security = 1

<cfif getAdminUser.RecordCount GT 0>
        <cfset AdminName = getAdminUser.vc_name>

Admin User Name: <cfoutput>#AdminName#</cfoutput>

This code is much more efficient and is easier to understand. The query isolates only the records and columns that need to be used in the code. It will only return one record if any records have a security level of 1.

Avoiding Common Bottlenecks

The preceding example illustrated a simple way to write more efficient code. Let's look at other coding bottlenecks and discuss ways to avoid them.

Querying a Database

Pay careful attention to the number of records to be returned and the structure of the SQL itself when writing queries to retrieve data for outputting on the screen or into form variables. A bottleneck, common to complex queries, results from a query returning more records than are required and using only a subset of the returned records. Such a query should be rewritten to return only the required records.

In addition, database software is much more efficient at processing database requests than Cold-Fusion is. For a highly scalable Web site, it is best to create views for selecting data and stored procedures for inputting, adding, and deleting data from of the database. Design your ColdFusion templates to call these views and stored procedures to interact with the database. Asking the database server to perform this kind of work is much more efficient and tends to stabilize performance. Here is an example of a poorly coded set of queries to retrieve data. This code is not scalable and will affect Web site performance. Notice that the same table is queried twice to return different data. One query, in this case, is sufficient:

<cfquery name="getUser" datasource="db_Utility">
         SELECT vc_name FROM tbl_User WHERE int_userID = 26

<cfset userName = getUser.vc_name>

Hello <cfoutput>#userName#</cfoutput>

some more code here ......

<cfquery name="getUserInfo" datasource="db_Utility">
         SELECT int_userid, vc_username, vc_password, vc_email,
                dt_createdate FROM
tbl_User WHERE vc_name = '#userName#'

Here is the information you requested:<br>

<cfoutput query="getUserInfo">
        Your User ID: #int_userid#<br>
        Your User Name: #vc_username#<br>
        Your Password: #vc_password#<br>
        Your Email: #vc_email#<br>
        Date you joined: #dt_createdate#

As you can see, only one query needs to be called to return this data. This is a common mistake.

Absolute Path, Relative Path, and Other Links

One of the more common problems I have seen in Web applications is confusion about when to use the absolute or relative path for a link. Both methods can be employed while coding, but you must be cognizant of the impact of each approach when you are coding for a clustered environment. Questions to ask before utilizing absolute or relatives paths in your application include:

  • Will the link be moved at any point in time? If the answer is yes, an absolute path will be a more viable option, since it is assumed the new path can be mapped on the Web server to be the same mapping as before.

  • Does the path exist under the current subdirectory? If the answer is yes, then relative path mapping will work.


Relative path is relative to the current template. Absolute path is the path relative to the root of the Web site.

Hard-coding links will cause problems with clustered machines. Say that you have an upload facility on your Web site that allows users to upload documents. The code needs to know a physical path in order to upload the documents to the correct place. Server 1 contains the mapped drive E pointing to the central file server where all the documents are stored. The file server has an uploadedfiles directory located on its D drive, so the path can be set to e:\uploadedfiles. But Server 2 does not contain a mapped drive named E pointing to the file server. If you deploy your code from Server 1 to Server 2, the upload code will break because Server 2 does not know where e:\uploadedfiles is. It is better to use Universal Naming Convention (UNC) syntax in the upload path: \\servername\d\uploadedfiles. Note that having one file server in the configuration described creates a single point of failure for your Web site.


Universal Naming Convention (UNC) is a standard method for identifying the server name and the network name of a resource. UNC names use one of the following formats:


Nesting Levels Too Deeply

Nesting is considered a valuable tool for developers to build complex applications. Nesting too many levels, however, can cause code to become unmanageable and virtually incomprehensible. A developer working on a Web site where nesting is deep may eventually stop trying to follow all of the levels and write new work-around code. This approach may affect how the Web site performs. Too many nested levels in code can also affect performance because nested code almost always attempts to perform too many functions at once. Simplify your applications to perform fewer a functions with each call. Doing so will streamline the application, reduce nested layers, improve code readability, and increase performance.

4. Keeping Web Site Servers in Sync | Next Section Previous Section

Adobe Press Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Adobe Press and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Adobe Press products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.adobepress.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020