Cactus farming is very easy. You pretty much just plant a cactus block and wait for it to grow. However, there are a few tips and tricks which could make it all a little easier and more efficient.
The main things you need to know about growing cacti is that they only grow on sand, the cannot be placed next to other blocks, they will destroy any block that is dropped on it and they will harm players and mobs who come into contact with it.
This means you have to build a zig zag pattern for the cacti to grow, but you cannot build a checkerboard style field, like the one in the image below, as you won’t be able to reach the cacti in the middle without getting hurt by the cacti on the outside.
Instead, we use a path between every 2 block wide row of cacti, as this allows us to maximize the amount of land we use, without wasting too much space in paths. With this setup you will lose some cacti blocks when they fall on other cacti during harvesting, but it’s almost impossible not to lose any (without wasting time).
You could also go for paths between each single row, but this uses up too much space and even in that setup you’ll end up losing some cacti blocks.
It’s possible, and very easy, to automate your cactus farm. You could make a fully automatic and semi automatic farm, the only difference being the piston input.
In the example below we’ve build 2 rows of pistons and cacti, which is about as compact as you can get (though the redstone could be more compact). The pistons will push forward when we pull a lever, which will cause the piston arm to reach any cactus block higher than the cactus base. Because cactus blocks cannot be placed next to other blocks, this cactus block will pop out when the piston arm reaches it. Any cactus blocks on top of that will also fall, as they’re no longer supported.
Most of the fallen cactus blocks will fall into the water below, which will carry those blocks with the current to any collection spot you like. However, many cactus blocks will either be destroyed by falling on other cacti or they’ll fall just on the edge of the sand block. Unfortunately this is a prize you have to pay for (semi-)automatic farms.
To make your farm fully automatic, all you have to do is add a timer between each input. You could do this with redstone clocks. One effective clock would be a despawn clock, which uses the 5 minute despawn time of blocks with wooden pressure plates, to send a signal once every 5 minutes, by simply adding a signal inverter between the pressure plate and whatever it has to be connected to.