R5-D4 was one of the last R5 units ever built. Industrial Automaton cut one corner too many by the time they produced the unwarranted R5 addition to their otherwise successful astromech program. In an effort to cash in on the popularity of their line, they developed the R5 as an "economical" version of the R2, lacking many of the amenities that the more expensive model featured. Such cost cutting negatively affected the R5 personality matrix, and the finished droids often developed sullen and acerbic character traits. The product line was a failure, and Industrial Automaton attempted to recoup losses by reusing the R5 frame as part of their R2-AG4 and R4 astromech lines.
R5-D4 was abandoned by many owners and switched hands over the course of long, miserable decades. The little droid became quite jealous of the newer, more popular models and made no secret of his spite.
Red, as he was often simply referred to was purchased by Owen Lars from the Jawas, just before he purchased C-3PO. R2-D2 had modified R5-D4 so that its motivator would fail, drawing attention to himself. When the battered little droid rolled away from the sales line, his motivator shorted out and he blew his stack. Rather than buy the worthless hunk of junk, Owen instead bought R2-D2. R2's plan had worked.
After being passed up by Owen Lars, R5-D4 then spent a number of days riding along inside the Jawa's sandcrawler, until the sandcrawler was attacked by Imperial forces looking for R2-D2 and C-3PO. R5-D4 was in no condition to move, and bided his time until another group of Jawas came by to claim the left-over machinery.
R5-D4 was stolen from the Jawa sandcrawler by a mischievous Squib trader named Macemillian-winduarté. The trader sold the droid to Alliance historian Voren Na'al, who had the little red unit reprogrammed and refurbished.
With the help of Momaw Nadon, Na'al sold R5-D4 to the local Imperial prefect's assistant administrator within the government offices of Mos Eisley, and the droid became a valuable source of intelligence data. There, R5-D4 recorded everything that he heard and saw, holding the data until it could be recovered by Nadon.