Search code examples
javatomcatjboss

Java Web Application Image Transfer


Using Tomcat or JBoss, how do I transfer and save dynamic image content from an image repository on one server to a number of other servers (machines) on the same network without writing a Client/Server application?
The web site I am building contains a large number of images that will only be saved and shared on one machine. All of the web app servers need to be able to access these files.


Solution

  • Kermit Love, here are a few suggestions based on your requirements. Note that none of these are based on Java nor specific to Tomcat / JBoss.

    Option 1 : Using a NAS or a Shared Directory

    Using a specific hardware (NAS), a file server (Samba) or a simple shared directory over the network would allow all you machines to access the content through the network.

    Pros:

    • This solution can scale
    • Setup is easy

    Cons:

    • The network overhead may slow down your global solution depending on your needs (access frequency, images sizes, ...)
    • No high-availability (fault tolerance)

    Option 2 : Using an upfront server dedicated to load balancing / reverse-proxy / serving files

    You can use a simple Nginx / Apache server to deliver "static" content while routing trafic to your application servers.

    Pros:

    • Efficient way to serve images to clients.
    • You separate the concerns (business logic vs serving files).

    Cons: No high-availability (fault tolerance)

    Option 3 : Using rsync to synchronise file systems

    You can define a cron based rule to run a rsync command every N seconds/minutes to ensure all your machines have the data available.

    Pros:

    • Easy to setup
    • Free (no need extra hardware, for now)
    • (slightly) better performance in the long term than option 1 (no repeated network overhead).

    Cons:

    • Yet an extra-process
    • Doesn't scale horizontally
    • Files won't be immediately accessible