Q:

Echo server built with Netcat and FIFO fails when used with rev

I'm playing around with Netcat, and I've successfully made an echo server like this:
mkfifo fifo
cat fifo | nc -l 3000 > fifo

Next, I'd like to apply some transformation to the data before it's echoed back:
cat fifo | nc -l 3000 | rev > fifo
# Or:
cat fifo | rev | nc -l 3000 > fifo

But neither of the above works.  The same happens when I use any text-tranforming program, not just rev.  But if I replace rev with cat, it works again:
cat fifo | nc -l 3000 | cat > fifo

This leads me to believe there's something special about how cat uses standard in and standard out. ( As compared to rev, tr, and other similar text-transforming programs.) 
What's going on here?  Why does inserting rev into the pipeline break the echo server?  Is cat indeed special, and if so, how? 

A:

This is due to buffering.  glibc automatically buffers output when stdout is not a terminal.  
efficiency.  
You can see the same effect in your terminal where rev reverses each line as you type it, while rev | cat does not.  
To fix it, you have to get your command to not buffer.  GNU has a stdbuf tool for doing this for arbitrary commands:
cat fifo | nc -l 3000 | stdbuf -o 0 rev > fifo

The interactive command scripting tool expect also comes with an unbuffer command to do the same.  
Buffering is only efficient when combining multiple small writes into a large one.  Programs that just copy from one place to another (like cat and dd) don't benefit from buffering and therefore don't do it.