Best Practices
Web services have been around for a while and have generated significant hype. Along with the advantages of cross-platform compatibility are some drawbacks. Although the distributed computing environment of web services is widely recognized as the way of the future, it carries the baggage of network latency and additional translation time. The actual overhead of running a web service is not as bad as perceived, but it is a factor to consider when selecting parts of systems to expose to the world. Careful testing and optimization can reduce this potential problem significantly. Here are several general principles to consider when programming and designing web services:
- Use coarse-grained web services. Network latency can be the biggest performance bottleneck. Try to reduce calls to the server. Call a web service once and use a query of queries to return the detailed information for display.
- Secure your services. Never publish your web service without proper security in place. See the discussion about securing your web services earlier in this chapter for details.
- Use a server-level timeout. Aim for a timeout value of 1 to 3 seconds; waiting for a web service from a busy server to return can eat up all threads on your server and potentially can bring it down.
- Preferably, call long running web services from a scheduler or <cfthread> and look for caching possibilities. See Chapter 14 for information about schedulers and Chapter 16 for information about caching.
- Use stateless web services whenever possible.
- Include ColdFusion types in WSDL and limit the use of complex data types in web services that interact with other platforms. Other platforms may not be able to understand deeply nested types.
- Monitor your web service calls to understand their use. You can use ColdFusion server monitoring, which monitors web service calls separately from other types of request. With just the basic monitoring enabled, you can get valuable information about web service requests, running or queued. And on the basis of this information, you can tweak your server settings and also change the application code.