Sequential and Serial Vs Random File Access

Sequential and Serial Vs Random File Access

Serial file access means that data has to be accessed in the order that it was written. It is not possible to move around freely within the file from one position to another. If a data item is required that is at the end of a file then all of the preceding contents of the file must first be read before the data item can be reached.

With random access it is possible to move around to different points within the file at will. If the data item required is at the end of the file, then it is possible to simply skip to the end and read the data without first having to read all of the preceding data in the file.

Sequential file access is a subtle variation of serial access. In a sequential file data is stored in a sorted order. Imagine a book of phone contacts where someone has stored the list in alphabetical order by name. If searching for the name “Smith”, there is no point searching further than names beginning with “S” as the section T through Z cannot contain the contact. However in an unsorted contact book, you would need to search to the end to be certain that Smith does not exist. The sorted contact book would be sequential but the unsorted one would be serial.

The reason why files may only be accessed serially can be due to the nature of the hardware on which the files are stored. While rarely encountered in consumer products, magnetic tape is still sometimes used for backup purposes in professional computing environments. Data on tape can often only be accessed in the order in which it is written.

Sometimes hardware is technically capable of skipping around to different positions within a file but changing position is very slow. Accessing the file serially can be considerably faster. This is often the case with storage devices that involve mechanical components. It may be technically inaccurate to describe a tape as being entirely serial as it can be rewound, but it has such a poor random access capability that it may as well be serial.

Most data storage devices in use today can access data in a random fashion and the performance cost of changing position in the file is becoming less of an issue. These days serial file access is more usually a result of software imposed limitations.

An example of a software limitation that can result in serial file access is downloading a file from a website. Often a website will only permit a file to be downloaded in full and partial files cannot be retrieved. The hardware on which the website runs is perfectly capable of delivering partial files and it would be possible to write software that could deliver part of a file but the website operator does not consider implementing the feature worthwhile. Perhaps 99% or more of customers only ever download a file in full and it is not worth the trouble to offer anything else as random access is more complex.

Another example of software limited serial file access is due to the way files are encoded. If a file is compressed it may not be possible to read the end of a file without first reading the start of the file. This is due to interdependencies in the file format where understanding one part of a file relies on information that is located in a different part of the file.

Sometimes serial file access may be the only practical alternative. A storage device may allow you to skip around within a file with very high performance but you need to know where to look in order to avail yourself of the feature. If you are searching for a particular word within a book, the fact that the book allows you to skip directly to any page is of no use if you do not know on which page the word is located. You will have to read the book from the beginning until you find the word, hence for practical purposes the book has serial access even though it technically has random access.

This all changes however if the book has an index. Now we know on which page every word occurs and the random access capabilities of the book become useful. Files can be given indexes as well in just the same way as a book. Instead of page numbers the index words refer to positions in the file. The words in the index to a file can be known as keys.

Credit: Tape image by Don DeBold