Generation and application of ultrafast X-ray sources