David sinned because his pride caused him to take a census of Israel. This failure resulted in the death of 70,000 men of Israel through a plague. But the judgement of God was stopped at the threshing floor of Araunah because David built an altar there to sacrifice burnt and fellowship offerings to God.
The altar that David built at Araunah's threshing floor was an altar to his sin and subsequent repentance. This altar arising from David's failure became the site for the new temple that Solomon would build for the Lord. God often uses our human failures to demonstrate His grace and favour. Like David, we should not wallow in self-pity when we have sinned; rather we should cast ourselves upon God's grace and rise up again to walk in His favour. When we acknowledge God's grace, we can turn even our failures into opportunities for divine favour.
Father, what a gracious God You are! Even in our failures, You have shown favour. Amen.