What does this barrel adjuster do on the rear derailleur (SRAM Apex 1)?
It lengthens or shortens the housing length to adjust the lateral position of the derailleur cage. It's used to adjust derailleur 'indexing' so that the chain sits properly on the cassette sprockets.

Mountain bike shifter units have barrel adjusters, road bikes use this one as well as having frame mounted or 'in-line' adjusters some where on the housing run.

This video from park Tool Company has a good visualization of how it works: