Now, a bottleneck of the current virtual currency system is the time and cost needed to carry out transactions. To overcome this problem and to provide more convenient transactions, an exchange market for virtual currency has been developed. However, the existing virtual currency exchanges are centrally controlled by exchange organizers. As a result, they are prone to malicious attacks, and in fact, several of the hacking incidents on the exchange has been reported.
Just In 2019, over $290 million worth of cryptocurrencies were stolen and over 500,000 login information were leaked from Centralised Exchanges. More people are realizing these risks and are turning to Decentralized Exchanges (DEXs) which are using smart contracts and “on-chain” transactions to reduce or eliminate the need for intermediary. 
The decentralized exchange solves this problem and is based on an electronic payment system based on cryptographic proof instead of trust, allowing any two willing parties to transact directly with each other without the need for a trusted third party. Transactions that are computationally impractical to reverse would protect sellers from fraud and routine escrow mechanisms could easily be implemented in order to protect buyers.
The decentralized exchange (DEX) is a new DApp that has been developed to cope with these weak points of centralized marketplaces. DEX allows a seller and a buyer of crypto assets to make a direct exchange in a decentralized manner on blockchain. Data (crypto assets and transaction records) is held in a decentralized manner so that DEX does not present itself as a single point of failure to attackers. Furthermore, because the system is open to the public, transactions can be made in a much more transparent fashion. 
The main feature of a DEX is a feature called “atomic swap”, which is code on the blockchain that allows two parties to exchange tokens/crypto assets without involving an intermediary party, and avoids one party defaulting on the transaction, which would damage the counterparty.
In a DEX, unlike a centralized exchange, participants manage their own crypto assets in their own wallets. When there is an exchange between two parties, the exchange occurs directly between the two wallets instead of going through a longer process that involves using a trusted third party. This direct exchange process is called ,,atomic swap.”