That's the way the cookie crumbles, literally 'esa es la manera como se desmorona/desmigaja la galleta', is an idiom used when you mean 'así es la vida, así son las cosas, qué le vamos a hacer'. Apparently, this idiom began to be used in the 1950s in America, though some linguists date it at least three decades earlier.
As is often the case, the idiom soon found its way into Britain, and now it's known practically in the whole English-speaking world.
That's the way the ball bounces, literally 'así es como la pelota rebota', is a common synonym. Both idioms are rather colloquial in style, in the line of the Spanish 'no hay más cera que la que arde', which has a similar meaning.
Going by the book
Hace 5 semanas