Scenario: Applications C and P run on the same machines, but are implemented in different programming languages. P contains the functionality that can return a list of addresses given a postcode and C needs to reuse this functionality.
If the pieces of code run on the same machines we could implement a file-based communication pattern. We have two programs: C and P. They can communicate via the file system. There are various ways, their communication could be implemented:
- Append request and responses to a file
- Append request and responses to multiple-files i.e. one for requests one for responses
- Write (i.e. clear the content) requests and responses to a file
Let's pick number 2 to illustrate by example. We have two files: postcodes.txt and addresses.txt.
- C writes to postcodes.txt and monitors addresses.txt
- P writes to addresses.txt and monitors postcodes.txt
Let's suppose that line in postcodes.txt is respective to addresses.txt. Although this pattern is ridiculsly simple, it presents a number of challenges:
- It hardly real-time. There will be a lag between C writing and P reading and vice-versa.
- File locking problems. Don't read addresses.txt when the data is being read.
- Ad-hoc file formats. C and P must agree on the file format.
- And indeed probably the filename itself
- It is hard to scale for multiple clients
- A lot of housekeeping
- Cleaning files otherwise they will grow
- Alternatively delete files when not needed
- What if the file is corrupted?
For the remote file based communication, the situation is similar, but in addition one has to decide how to communicate between them i.e. how to transfer or access the files e.g. sockets.