--- id: automatic-compaction title: "Automatic compaction" --- In Apache Druid, compaction is a special type of ingestion task that reads data from a Druid datasource and writes it back into the same datasource. A common use case for this is to [optimally size segments](../operations/segment-optimization.md) after ingestion to improve query performance. Automatic compaction, or auto-compaction, refers to the system for automatic execution of compaction tasks issued by Druid itself. In addition to auto-compaction, you can perform [manual compaction](./manual-compaction.md) using the Overlord APIs. :::info Auto-compaction skips datasources that have a segment granularity of `ALL`. ::: As a best practice, you should set up auto-compaction for all Druid datasources. You can run compaction tasks manually for cases where you want to allocate more system resources. For example, you may choose to run multiple compaction tasks in parallel to compact an existing datasource for the first time. See [Compaction](compaction.md) for additional details and use cases. This topic guides you through setting up automatic compaction for your Druid cluster. See the [examples](#examples) for common use cases for automatic compaction. ## Auto-compaction syntax You can configure automatic compaction dynamically without restarting Druid. The automatic compaction system uses the following syntax: ```json { "dataSource": , "ioConfig": , "dimensionsSpec": , "transformSpec": , "metricsSpec": , "tuningConfig": , "granularitySpec": , "skipOffsetFromLatest":