How are stoplights timed in order to keep traffic moving?

Well, if you're in Houston like I am you might question this concept entirely.

Traffic lights are timed in order to clear congestion (the traffic kind)
and keep everyone moving along. A traffic control department has to
keep in mind how fast traffic should move when they are determining the
timing of lights in a certain area, as well as the length of a city
block, are streets one-way or two-way, and the volume of traffic at
different times of the day.

For example, the stoplights in downtown New York City are gauged for
traffic moving at 23 to 30 miles per hour. If a light on 40th Street
turns green, the lights on 41st Street will change to green 6 seconds
later - and the ones on 42nd Street will change to green 6 seconds after
the one on 41st Street changed.

This system works great on one-way streets, as you will (in theory) keep
moving along as long as you are maintaining the previously mentioned 23
to 30 mph speed - go any faster and you will be constantly beating the
light, hitting your brakes and waiting for the light to change; go any
slower, and eventually you will be caught at one of the following lights.

If you're traveling on a two-way street a group of signals (i.e., four
at a time) will all change at once. This type of system generally
depends upon the distribution of stoplights and the length of the block.

The signals in our New York City example are based on a 90 second cycle:
they stay green for 60 seconds on main streets and 30 seconds on side
streets.