MYSQL DBAs usually try to minimize replication slave lag, but there are scenarios where you need non-zero lag.
Production applications often write to a MySQL master and read from one or more slave databases.
Development and Test environments (sandboxes) seldom simulate possible replication lag though.
Galera
With a typical installation of Galera, replication lag is usually less than 0.1 second.
You can make a node lag more than that by either shrinking the transaction log size, using large transactions, or both.
You can measure lag by using or modifying one of the causality test scripts included with Galera.
Continuent
You can configure slave lag with the time-delay filter.
You can see what the lag is in the appliedLatency value.
MySQL Built-in Replication
An easy way to do that in MySQL 5.6 is to install two MySQL databases in your sandbox, then configure delayed replication:
mysql> CHANGE MASTER TO MASTER_DELAY = N;
For MySQL 5.x, if you can install the Percona toolkit, then you can use the pt-slave-delay program.
Otherwise, you can use the following commands manually to do something similar:
mysql> STOP SLAVE SQL_THREAD; mysql> SELECT SLEEP(10); mysql> START SLAVE SQL_THREAD;
Or programmatically in 5.x, like this pseudocode:
Loop:
STOP SLAVE; # on slave
SHOW MASTER STATUS; # on master, parse out File and Position values
SELECT SLEEP(3);
START SLAVE UNTIL MASTER_LOG_FILE='theMasterFile',
MASTER_LOG_POS=theMasterPosition; # on slave
SELECT MASTER_POS_WAIT('theMasterFile', theMasterPosition); # on slave, optional
# detect any slave errors and report if found
A variation on the above pseudocode, if you don’t want to connect to the master, is to parse SHOW SLAVE STATUS for Master_Log_File and Read_Master_Log_Pos:
Loop:
SHOW SLAVE STATUS;
# detect any slave errors and report if found and
# parse out Master_Log_File and Read_Master_Log_Pos values
STOP SLAVE;
SELECT SLEEP(3);
START SLAVE UNTIL MASTER_LOG_FILE='theMasterFile',
MASTER_LOG_POS=theMasterPosition;
SELECT MASTER_POS_WAIT('theMasterFile', theMasterPosition); # optional
Note that show slave status and stop slave can block or even deadlock with various versions of MySQL, and when FTWRL (Flush Tables with Read Lock) is used.
MySQL Bug #68460: blocked with FLUSH TABLES WITH READ LOCK + SHOW SLAVE STATUS
A tip from the wikipedia project is to add the replication lag to application cookies. Deciding what to do with that info is left as an exercise for the reader.
dev.mysql.com: Delayed Replication,
Pausing Replication on the Slave, Start Slave
Stopping the slave exactly at a specified binlog position
MySQL 5.6 FAQ: Replication
xaprb.com: Introducing MySQL Slave Delay (2007)
Percona Toolkit – pt-slave-delay
George Betak from Yahoo! gave an excellent talk on “Computer Vision and Behavior Driven Visual Automation in L10n and i18n QA” at 
