Servlet best practices for scalability


Web tier: servlets, JSP, Web frameworks: Servlet best practices for scalability

  1. Servlet best practices for scalability (2 messages)

    The clustering promotes high availability and scalability. The considerations for servlet clustering are:

    --Objects stored in a session should be serializable to support in-memory replication of sessions. Also consider the overhead of serializing very large objects. Test the performance to make sure it is acceptable.

    -- Design for idempotence. Failure of a request or impatient users clicking again can result in duplicate requests being submitted. So the Servlets should be able to tolerate duplicate requests.

    -- Avoid using instance and static variables in read and write mode because different instances may exist on different JVMs. Any state should be held in an external resource such as a database.

    -- Avoid storing values in a ServletContext. A ServletContext is not serializable and also the different instances may exist in different JVMs.

    -- Avoid using* because the files may not exist on all backend machines. Instead use getResourceAsStream().

    -- By Author of the book "Java/J2EE Job Interview Companion" at
  2. Are you trying to just plug your books?
  3. ServletContext as an interface is not serializable but finally it depends on the implementaion of ServletContext by the container . Hence if the implementation is serializable it can still be passed across JVMs for clustering .