Splitting web,db,cache into three items is a job I wouldn’t hand to cut in a loop. Bash can do it in one read.
Set IFS to the separator just for this command, and -a stores the pieces in an array:
line='web,db,cache'
IFS=, read -ra hosts <<< "$line"
echo "${#hosts[@]} hosts, first is ${hosts[0]}"
for h in "${hosts[@]}"; do echo "ping $h"; done
-r stops backslashes from being treated as escapes, which you almost always want. Because IFS=, sits in front of read, it only changes the separator for that one command and your global IFS stays as it was.
It handles one line only. If the input has newlines, read stops at the first one, so for multi-line input use mapfile instead.
Whitespace behaves differently from other separators. With a comma, a,,b gives you an empty middle element, which is often right for CSV-like data. With spaces or tabs as separator, runs of them count as one and leading spaces disappear. And real CSV with quoted fields that contain commas is too much for this trick; reach for a proper parser there.
Further reading: Bash manual: Bash Builtins (read)