An example of use is to start a 1s transaction. One-time clients

Last time we looked at the simplest method using the built-in 1C language. On practice transactions much more often used in conjunction with the design. This allows, in the event of an error, to continue executing the code, as well as provide an adequate error message to the user and write information to the registration log or to a log file for subsequent analysis by the system administrator.

If we turn to the technical documentation or the ITS disk, we will see that 1C recommends the following method of organizing a transaction in an attempt

Attempt //1. Start of transaction. StartTransaction() ; //2. A block of operations performed in a transaction. //3. If all operations are successful, we commit the transaction. CommitTransaction() ; Exception //4. If errors occur while executing the code, cancel the transaction. CancelTransaction() ; //5. If necessary, record in the log book. //6. If necessary, display a message to the user. EndAttempt ;

Actually, the code does not require any special explanation. If in progress attempts When executing transactional code, an error occurs, we immediately fall into the block exception, i.e. before method CommitTransaction() we just don't get there. Well, in the exception, we cancel the transaction accordingly and, if necessary, display an error message and write the information to the log. It is highly desirable to record errors in the log book, especially for those operations that are performed without user participation (for example, routine tasks). This will allow you to analyze the error later. Instead of logging, you can arrange for messages to be sent to the administrator by email.

Now, armed with new knowledge, let's try to modify the code discussed in the article about . Let me remind you that we considered the entry in the directory Goods and to the information register Price according to the following scheme:

&OnServerWithout Context StartTransaction() ; //record a new product Product = Directories. Goods. CreateItem() ; Product. Name = "Hole Punch" ; Product. Write() ; //write down the price RecordSet = InformationRegisters. Price. CreateRecordSet() ; NewRecord = RecordSet. Add() ; NewRecord. Period = CurrentDate() ; NewRecord. Product = Product. Link; NewRecord. Amount = 100 ; RecordSet. Write() ; CommitTransaction() ; End of Procedure

Now let's put the transaction in a block Attempt Exception. Most likely, errors can only occur at the time of entry into the directory or information register, so we will take the preliminary preparation outside the transaction.

&OnServerWithout Context Procedure RunTransactionOnServer() //create a new product Product = Directories. Goods. CreateItem() ; Product. Name = "Hole Punch" ; //Create a record with a price RecordSet = InformationRegisters. Price. CreateRecordSet() ; NewRecord = RecordSet. Add() ; NewRecord. Period = CurrentDate() ; NewRecord. Amount = 100 ; //Execute the transaction in attempt Attempt to StartTransaction(); Product. Write() ; NewRecord. Product = Product. Link; RecordSet. Write() ; CommitTransaction() ; Exception CancelTransaction() ; Message = New MessageToUser; Message. Text = ; Message. To report() ; LogRegistration( "An error occurred while recording the product and its price") ; EndAttempt ; End of Procedure

What NOT to do

Those who are just starting to work with transactions often have a desire to do it this way

StartTransaction() ; Attempt to StartTransaction(); //Operation block CommitTransaction() ; Exception CancelTransaction() ; EndAttempt ; Attempt to StartTransaction(); //Operation block CommitTransaction() ; Exception CancelTransaction() ; EndAttempt ; CommitTransaction() ;

Or in a loop

StartTransaction() ; For each Data From Data Array Loop Attempt to Start Transaction() ; Data. Write() ; CommitTransaction() ; Exception CancelTransaction() ; EndAttempt ; EndCycle ; CommitTransaction() ;

At first glance, we did everything in accordance with the recommendations of the 1C company. But the fact is that the 1C platform does not support nested transactions. That is, purely technically, it is possible to write this way. But at the same time, all nested transactions do not form new ones, but belong to the same top-level transaction. This way, if one of the nested transactions fails, the next nested transaction cannot be committed. The system will display a message like: “Errors have already occurred in this transaction!”. Let's demonstrate this with an example. Let's say we decide to record two goods, each in its own transaction. And let's make these transactions nested in the third. Next, we will artificially cause an error in the first transaction using the method Raise Exception:

&OnServerWithout Context Procedure RunTransactionOnServer() StartTransaction() ; Attempt to StartTransaction(); Product = Directories. Goods. CreateItem() ; Product. Name = "Table" ; Product. Write() ; Raise Exception "Product entry error."; CommitTransaction() ; Exception CancelTransaction() ; Message = New MessageToUser; Message. Text = ErrorDescription() AttemptStartTransaction() ; Product = Directories. Goods. CreateItem() ; Product. Name = "Chair" ; Product. Write() ; CommitTransaction() ; Exception CancelTransaction() ; Message = New MessageToUser; Message. Text = ErrorDescription() ; Message. To report() ; EndAttempt ; CommitTransaction() ; End of Procedure

As a result of performing this procedure, we will see the following in the message window:

(ExternalProcessing.TransactionsAtTrying.Form.Form.Form(20)): Error writing item. (ExternalProcessing.TransactionsAtTrying.Form.Form.Form(40)): Error when calling context method (Write): Errors have already occurred in this transaction!

Thus, organizing nested transactions in 1C is absolutely pointless.

Possible options

Now let's go back to the option where we recorded the product and the price for it. If we have an error while performing a transaction, it will be difficult to understand at what point it occurred - when recording the product or when recording the price, since both occur within the same attempt. To determine where the error occurred, we need to wrap each write operation in its own attempt and avoid nested transactions. To do this, we introduce a Boolean variable Refusal and depending on its value at the end of all operations we will commit or cancel the transaction.

&OnServerWithout Context Procedure RunTransactionOnServer() // Start the transaction Refuse = False ; StartTransaction() ; // Trying to record the product Attempt Product = Directories. Goods. CreateItem() ; Product. Name = "Hole Punch" ; Product. Write() ; Exception Failure = True ; Message = New MessageToUser; Message. Text = "Error recording product"; Message. To report() ; EndAttempt ; // Trying to record the price AttemptRecordSet = InformationRegisters. Price. CreateRecordSet() ; NewRecord = RecordSet. Add() ; NewRecord. Period = CurrentDate() ; NewRecord. Product = Product. Link; NewRecord. Amount = 100 ; RecordSet. Write() ; Exception Failure = True ; Message = New MessageToUser; Message. Text = "Error while recording price"; Message. To report() ; EndAttempt ; // Commit or cancel the transaction If NOT Failure Then CommitTransaction() ; Else CancelTransaction() ; EndIf ; End of Procedure

We can do the same thing when we iterate and write any data in a loop. In this case, we will be able to obtain a list of all data with errors, if any.

The word “transaction” came to us only in the late nineties. This was the period of development of the modern banking system and the general computer boom. Then this concept began to appear in colloquial and literary speech. And while ordinary people rarely encounter problems with programmers, everyone has to deal with banks. Almost any operation - from checking the status of an account to complex intra-bank payment transfers - can qualify as transactions. This word is present in banking operations almost more often than concepts such as “money” or “credit”. However, few of the bank's clients fully understand its essence.

Meaning of the word

Transactions are certain procedures for the interaction of any objects over a certain period of time. Such procedures were formed by programmers. They have a clear procedural character. Any transaction is a combination of three essential components:

  • request;
  • execution;
  • report.

The process of a normal transaction can be quite complex, but the result of this procedure has only two states. That is, the transaction may or may not be completed.

Bank transactions

What does the word "transaction" mean? What processes occur when it occurs? To be precise, transactions are any banking operations related to the movement of funds. But most often this term is used when using electronic invoices. Or it directly points to transactions with bank cards.

The phrase “conduct transactions” means operations using an electronic account. This includes paying utility bills, purchasing goods in a store using a plastic card, depositing salaries and scholarships, and many other money transactions.

Types of transactions

In banking, there are two types of operations:

  1. Online transactions are the manipulation of non-cash money by connecting to a banking center in real time. The most obvious example is working with a terminal.
  2. Offline transactions are the execution of a banking transaction without direct contact between the participants. For example, crediting employees' salaries. Funds are debited from the organization's account, and the employee only receives a notification about the replenishment of the balance of his current account.

To better understand the essence of banking transactions, let's consider several of their options.

Money transaction

The simplest example of such an operation is a transfer between your own accounts, receiving or depositing money, depositing cash through an ATM or terminal. Such transactions are usually carried out by the bank without commission. The situation is more complicated with transfers between two different persons - within the same financial institution, the transfer fee can reach 3%. If we are talking about different banks within the country, the commission will be even higher. The most expensive transfer is to foreign institutions, since, in addition to the commission, they often charge a so-called transaction fee.

Translations

Transfers from one account to another sometimes lead to annoying errors. The slightest inaccuracy in the spelling of the recipient's last name can result in blocking manipulation of the electronic security system. An automatic transaction will solve the problem. This happens, for example, when funds are credited to the recipient’s balance using a bank card number. This significantly reduces the likelihood of error. If the transaction is reset, the money is simply returned to the owner’s balance. True, this happens within ten or fifteen calendar days.

If the sender does not have a bank account, you can use a money transfer service. The most famous international operators are MoneyGram, Western Union, Anelik, Contact and others. The main advantage of such operations is the high transaction speed. The main disadvantage is the rather high commission.

What to do if a transaction fails?

In case of any unusual situation related to the transfer of funds, you must immediately report this to the bank or terminal operator. In this case, there is a high probability that the money will return to the sender’s balance or will be used for its intended purpose.
The operator will help you if:

  • During the transaction, a failure occurred (the program froze, the electricity went out), and the money was already gone. A call to the hotline will record your request. After checking and eliminating the error, specialists will be able to complete the operation manually.
  • The terminal or ATM did not issue a receipt for the transaction. The reason may be trivial - the lack of a cash register tape in the machine. After contacting the operator, you will be offered a duplicate receipt. Usually it is sent to the specified email address.
  • There is an error in the specified details. The money was gone, but the recipient never saw it.
    The operator can help solve this problem: for example, find an error in the recipient's account number. In this case, the money does not reach the client simply because of security rules. Such funds are not withdrawn by the bank, but are stored for 10 days in a special temporary account. If the sender contacts the financial institution on time, indicates the time of the transaction, the amount of the transfer and answers several questions, the money will be unblocked. After deducting the transaction fee, the amount will be returned to the sender’s balance.

As you can see, banking transactions are an interesting, necessary procedure in the life of each of us. Next time, when making a simple transfer or withdrawing money from a card, think about how much easier such manipulations make our lives. After all, by now you probably already know what transactions are. The meaning of the word is no secret to you.

Many people wonder what a transaction is? After all, this word comes up all the time, especially if a person works with money. If we take it globally - the sequence of data exchange operations, after which system changes are made.

The most common use of the term is in making money transfers and purchasing goods. It could be:

  • Cash withdrawal from an ATM or bank branch;
  • Purchasing a certain number of shares on the stock exchange;
  • Payment by card in the store.

As soon as the operation has been confirmed and the money has been sent, the transaction is considered successfully completed. Money is withdrawn from the account of the buyer or client of the institution, and the goods are transferred to the individual. We can say that the transaction serves as a way to voluntarily transfer money from a person’s account to the person providing the service. All transactions are recorded in the financial institution's database. It doesn't matter whether the operation was successful or not. For example, in case of incorrect crediting of funds to a bank card.

But don’t think that the concept of a transaction applies only to the financial sector. IT companies also often use this term, especially when it comes to database programming. In this case, the term will mean a certain sequence of changes made to the data base.

There are also two application options here. When an operation is approved, “Commit” is assigned to it, but if for some reason a refusal occurs, then “Rollback” is assigned. Most often, this happens when they wanted to divide one of the numbers by zero or entered an amount that does not correspond to what was previously entered into the database.

Kinds

The most common case of using a transaction is payment with a payment card from a bank on the territory of any shopping center, store or financial institution. The operation begins when the owner wishes to pay for the goods, after which he gives his bank card to the employee responsible for the cash register.

Next, the card is placed in a special terminal, where you only need to confirm the subsequent operation. To do this, you need to enter data and a predetermined PIN code. Next, the terminal will decide whether the entered password was correct or should be rejected. In any case, information about the transaction will be recorded in a specific database. This happens due to the transfer of data to the payment system servicing this card. And already at this stage, a full verification of the authenticity of the entered data takes place. After all, they may or may not be present on the payment slip.

But if everything is correct, the transaction is successfully completed and sent straight to the issuing bank. The production of this payment card was carried out through him. Then the information about the transaction is sent to the pressing center, where information about the rights to use the payment system is established.

It is worth noting that if an error or data discrepancy is detected at one of the stages, then the transaction is simply refused.

Areas of use

In different areas of application, different notations for the word “transaction” are used:

  • Economics refers to the transfer of funds from one flow account to another. This is especially true for purchase and sale transactions;
  • Operations with ATMs result in the issuance of cash to a client who used a bank card or account number to receive it;
  • A political explanation carries an agreement on mutually beneficial terms between two parties.

Much depends on the card issued by the bank. Debit and credit card are handled differently. The login priority, which is set by the financial institution that issued the card, also has a direct impact. Depending on these factors, the speed of the operation will vary.

Transactions with small amounts of money look simpler. If a person has specified a certain setting in the parameters, he will have the opportunity not to enter a password during the transaction. It will be carried out automatically and if there is a sufficient amount of funds in the account, they will be written off, and information about the operation will be recorded in the database.

Even areas completely unrelated to finance operate with the concept of “transactions.” Psychology is given as an example. Specialists in this field call a transaction the exchange of stimuli that arises during a conversation between two individuals. This application is somewhat far-fetched, but has a right to exist. Now you know what transactions are.

You need to know at least the above information about transactions, since it is simply impossible to do without them in the modern world. This means you should still have a minimal idea.

This article contains, to a large extent, theoretical information necessary to understand the importance of transactions and locks in 1C:Enterprise and the DBMS, and this is reflected in the performance of 1C:Enterprise. The article popularly describes the relationship between transactions and locks through isolation levels and concurrency problems.
This article does not provide practical advice for solving specific problems, but is the basis for understanding the following articles, which describe steps to optimize and improve 1C:Enterprise performance related to transactions and locks.

Productivity is directly related to 1C:Enterprise TRANSACTIONS

"Lock conflict during transaction:
Microsoft OLE DB Provider for SQL Server: Lock request time out period exceeded.
HRESULT=80040E31, SQLSrvr: SQLSTATE=HYT00, state=34, Severity=10, native=1222, line=1"

If 1C:Enterprise produces an error similar to this, then you are dealing with performance problems associated with blocking. Solving this kind of problem is not always trivial and requires certain special knowledge on the operation of DBMS and 1C:Enterprise, which neither 1C:Enterprise programmers nor system administrators often have. The next series of articles should fill the gap of this knowledge.

Transactions 1C:Enterprise

A transaction is an indivisible sequence of operations on data. It works on an all-or-nothing basis and translates the database
from one integral state to another integral state. If for some reason one of the transaction actions is not executable or some kind of system disruption occurs, the database returns to the state that was before the transaction began (the transaction is rolled back).

There are a number of requirements for the transaction mechanism (known by the abbreviation ACID): Atomicity (Atomicity), Consistency (Consistency), Isolation (Isolation), Sustainability (Durability)

Atomicity (Atomicity). This requirement is that all data that the transaction operates on must be either confirmed ( commit), or canceled ( rollback). There should not be a situation where some changes are confirmed and others are cancelled.

For 1C:Enterprise, the Transaction Atomicity properties ensure the logical integrity of the data. For example, when recording a document, its header data is written to one physical DBMS table, and the tabular part data to another. Recording a document in a transaction guarantees that the data in both physical tables (headers and table parts) will be consistent (it is impossible to write a table part without a header or vice versa).

Isolation (Isolation). Transactions must be performed autonomously and independently of other transactions. When many competing transactions are running simultaneously, any update to a particular transaction will be hidden from others until the transaction is committed. There are several levels of transaction isolation that allow you to choose the most optimal solution in terms of performance and data integrity. The main method for implementing these levels is locking, which will be discussed in this article.

Transaction Log (SQL Server)

Every SQL Server database has a transaction log that records all data changes made in each transaction. If the transaction for some reason did not complete (rolled back or was interrupted), then the SQL server, using the transaction log, cancels all transaction operations sequentially in the reverse order. This means that a long-running write transaction will take a long time and be canceled.

The transaction log is a critical component of the database and, in the event of a system failure, may be required to bring the database into a consistent state. The transaction log should not be deleted or modified unless the possible consequences are known.

Depending on the database settings (recovery model), the transaction transaction log can be trimmed (old transaction data is deleted) either automatically or manually (recovery model=FULL). Sometimes the system administrator forgets to trim the log and an error may occur: " The transaction log for database is full"

Physically, the MS SQL Server DBMS transaction log is located in the .LDF file (and the data file is .MDF).

Transactions in the 1C:Enterprise system

The 1C:Enterprise system implicitly calls transactions when performing any actions related to modifying information stored in the database. For example, all event handlers located in object and recordset modules associated with modification of database data are called in a transaction.

Example of an implicit transaction: sequence of events when posting a document from a form

In practice, you can determine that a 1C:Enterprise object record (for example, a document) is a TV transaction by conducting the following experiment: Try to post and close (click “OK” in the document form) a new document knowing in advance that it will not be posted (for example, by indicating a large quantity of goods to be written off) . Since the balances are checked at the document posting stage, in the "Processing Posting()" handler, by this moment the document itself should already be written to the database, since the document is written earlier between the "BeforeWriting()" and "OnWriting()" events. But after an error message appears (the required quantity is missing), we will find that the document is not recorded in the database (the modification flag “*” will remain and the document will not appear in the list). This happens because the transaction is rolled back after an error occurs (rollback).

Using an Explicit Transaction Call

Method StartTransaction() allows you to open a transaction. All changes to database information made by subsequent statements can then be either entirely accepted or rejected entirely. To accept the changes made, use the method CommitTransaction().
To undo all changes made in an open transaction, use the method CancelTransaction().

The degree of transaction isolation is determined by the isolation levels. The highest level of isolation ensures complete independence of the transaction from other concurrently executing transactions, but the degree of concurrency is also significantly reduced - other transactions have to wait for access to resources used in the current transaction. The lowest isolation level is the opposite: it provides the maximum degree of parallel operation, which leads to a significant impact of other transactions on the current one and the appearance of concurrency problems. In multi-user systems, a trade-off must be made between concurrency (simultaneous access to resources) and transaction isolation levels. The SQL language standard defines isolation levels that, when set, prevent specific concurrency problems.

Concurrency Issues

When executing transactions in parallel, the following problems are possible:
- lost update(eng. lost update) - when one data block is simultaneously changed by different transactions, one of the changes is lost;
- "dirty" reading(eng. dirty read) - reading data added or changed by a transaction that is subsequently not confirmed (rolled back);
- non-repetitive reading(English non-repeatable read) - when reading again within one transaction, the previously read data turns out to be changed;
- phantom reading(English phantom reads) - one transaction, during its execution, selects many rows several times according to the same criteria. Another transaction, between these selections, adds or deletes rows that fall within the selection criteria of the first transaction and ends successfully. As a result, it turns out that the same selections in the first transaction produce different sets of rows.

Let's consider situations in which these problems may arise:

Lost update

Dirty reading

If the previous problem occurs when writing data, then a dirty read is possible when one transaction tries to read data that another concurrent transaction is working on.
Suppose there are two transactions opened by different applications in which the following SQL statements are executed:

Non-repetitive reading

Suppose there are two transactions opened by different applications in which the following SQL statements are executed:

Transaction 1 Transaction 2
SELECT f2 FROM tbl1 WHERE f1=1;
UPDATE tbl1 SET f2=f2+1 WHERE f1=1;
SELECT f2 FROM tbl1 WHERE f1=1;

In Transaction2, the value of field f2 is selected, then in Transaction1 the value of field f2 is changed. If you try to select the value from field f2 again in transaction 1, you will get a different result. This situation is especially unacceptable when data is read with the intent of partially modifying it and writing it back to the database.

Phantom reading

Suppose there are two transactions opened by different applications in which the following SQL statements are executed:

Transaction 1 Transaction 2
SELECT SUM(f2) FROM tbl1;
INSERT INTO tbl1 (f1,f2) VALUES (15,20);
SELECT SUM(f2) FROM tbl1;

Transaction2 executes an SQL statement that uses all the values ​​in field f2. A new row is then inserted in Transaction 1, causing the SQL statement to be re-executed in Transaction 2 to produce a different result. This situation is called a phantom insertion and is a special case of non-repeating read.

Transaction isolation levels

The isolation level is a property of a transaction that determines the independence of the transaction from other transactions running in parallel.

The standard introduces the following four isolation levels, the use of which prevents certain concurrency problems:
- READ_UNCOMMITTED- unfixed reading. This isolation level solves the "lost update" problem, but it is possible to obtain different results for the same queries without regard to transaction commit (possibly a "dirty read" problem). This is the lowest isolation level used in a DBMS and provides maximum concurrency.
- READ_COMMITTED- fixed reading. This isolation level prevents the "dirty read" problem, but allows you to get different results for the same requests in a transaction (the possibility of "non-repeated read" is preserved);
- REPEATABLE_READ- repeated reading. This isolation level solves the "non-repeated read" problem. At this level, it is still possible to execute INSERT statements that lead to a “phantom insert” conflict situation. This level is useful if executing SQL statements are not affected by the addition of new rows;
- SERIALIZABLE- sequential execution. Third level. This level guarantees the prevention of all the concurrency problems described above, but accordingly, the lowest degree of concurrency is observed, since transaction processing (with access to the same resources) is carried out only sequentially.

The solution to the problem of parallel transaction access and isolation levels in the form of a table can be depicted as follows (“+” - the problem is eliminated):

Concurrency Issues and Isolation Levels Phantom reading Non-repetitive reading Dirty reading Lost update
SERIALIZABLE + + + +
REPEATABLE_READ - + + +
READ_COMMITTED - - + +
READ_UNCOMMITTED - - - +

At the SQL server level, you can set the isolation level yourself:
for the entire session, for example by directive
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE

for a specific query using the WITH construct
SELECT Name FROM Contracts WITH SERIALIZABLE

Find out the isolation level set in the current session
select transaction_isolation_level from sys.dm_exec_sessions
where session_id = @@spid

Automatic mode (the old mode that was used in 8.0) of data lock management uses transaction isolation levels REPEATABLE_READ And SERIALIZABLE provided by the database management system. These transaction isolation levels ensure consistent and consistent reading of data without requiring any additional lock management efforts from the developer.

Managed locking mode (starting from version 8.1) allows you to increase user concurrency in the client-server mode by using a lower level of database transaction isolation ( READ_COMMITTED); the same isolation level is set by default
and in MS SQL server. When writing data to a transaction, built-in language objects automatically lock the required data. But when reading, the developer needs to manage data locks in cases where business logic requires consistent and consistent reading of data in a transaction.

For version 8.3, managed mode uses isolation level READ_COMMITTED_SNAPSHOT.

conclusions

Transactions are a necessary DBMS mechanism that is actively used in 1C:Enterprise. To solve concurrency problems, transactions in a DBMS can be performed with different levels of isolation.

Isolation level used by 1C:Enterprise READ_COMMITTED solves the “Lost Update” and “Dirty Read” problems: changed data is locked until the end of the transaction for both reading and modification (an exclusive lock is imposed).

Isolation level READ_COMMITTED does not solve the "Non-repeating read" and "Phantom read" problems. To solve these problems, you need to use 1C:Enterprise controlled locks installed programmatically.

8.3 uses a more flexible isolation level READ_COMMITTED_SNAPSHOT.

Each client has his own repeating habits and traditions. Whether it’s a favorite day to shop, preferences for the average cost of a product, or for additional options for a product. All this information will help us encourage the client to make a second purchase and move from a new user to a regular customer.

We are moving from one-time purchases to regular customers

Well, you managed to convert the client. This is cool, but what next? According to statistics, from 30% to 80% of buyers in the e-commerce industry make an order only once during their entire life cycle. In the gaming industry, 60% of customers make a second order. How can we get loyal customers with such disappointing numbers?

This question worries marketers around the world. They work hard, putting all their efforts into converting clients from one-time clients to permanent ones. Be it initial orders in retail or deposits in online games. Why is the second order so important? If a customer makes their second order or makes a second deposit, the likelihood of making a third order increases tenfold compared to customers who have only made one order.

The table below combines data from ten leading ecommerce companies in Europe and the USA. As can be seen from the graph, the probability of making the next transaction increases with the number of current transactions.


Probability of the next transaction depending on the number of current transactions

Many companies group one-time customers into one group and use different techniques and messages to encourage a second purchase. Sounds like a good plan, right? One way or another, all clients in the group are one-time buyers. But we are here to discuss a different approach. This second method involves dividing a group of one-time customers into different segments based on the characteristics of their first transaction. Let's dive deeper and consider the prerequisites for such segmentation.

Day of the week

We'll start by analyzing the behavior of repeat buyers of the top 10 companies and try to understand whether there is a relationship between the day of the first order and the day of the second order. Let's start with an analysis of sports betting. In this theme, the client makes a deposit on the day when the most matches of his favorite team take place, usually on Saturday or Sunday. The likelihood of such clients returning and placing bets these days is quite high.

We collected data and ran tests and the results were the same as we expected. Basically, the second deposit was left on the same day of the week as the first. This can be seen from the maximum probability value located on the diagonal of the square.


Probability of making a second transaction depending on the day of the week of the first transaction in sports betting

The dependency between these two transactions can help better target promotional activities to different cohorts of one-time customers (in this case we have 7 groups based on the day of the first transaction) and remind the second transaction on appropriate days. A more interesting step is to test this hypothesis in retail.


Probability of making a second transaction depending on the day of the week of the first transaction in retail

We can see a similar situation. Customers make their second purchase on the same day of the week as their first. It is important to note that the dispersion in the retail industry was higher than in the sports betting industry. But the dependence itself manifested itself for each company. The most popular day for shopping is Monday, the least popular is Sunday. If we consider the dependencies between orders for only one brand, we get this.


Probability of making a second transaction depending on the day of the week of the first retail transaction for one brand

We have a simple explanation for this behavior in sports betting, but why do we see this result in retail? The reason may be that buyers have certain patterns in their lives. You go to the gym on Thursdays and Fridays, hang out with your family on the weekends, stay late at work on Mondays, and meet friends on Fridays. The buying pattern doesn't look strange considering all the others.

Times of Day

As you might have guessed, we tested similar hypotheses for time of day. Is there a correlation between the time of day of the first order and the second, if the second order was made at least seven days later? We divided the day into 4 periods: night, morning, evening and afternoon - and checked the distribution of second orders for each time period for 6 brands.


Probability of a second order depending on the time of day of the first order

The relationship between the first and second order by time of day seems obvious. Customers who order late at night for the first time are likely to place a second order at the same time.

Cost of goods in the order

As marketers, we strive to increase the number of items ordered. Upselling is a way of life in the marketing world, and if it's not, it should be. But should we always try to upsell a product? Is this the best solution for all of our clients? In our analysis, we examined whether the cost of goods in the second order increases compared to the first.

Different brands are used as data sources, so for each brand we identified separate segments with the value of the product. This resulted in 6 price groups.


Probability of the cost of the second order depending on the cost of the first order

Most of the customers whose orders were placed in the low price range remained in the same range in the second order.

Conclusion

Our analysis above shows what we can learn from the first orders. The main thing we need to remember is that we should not put all one-time clients in one group. It is worth segmenting customers depending on their day of the week and time of purchase, and the cost of the order.
Using these methods and steps will help you better understand how to increase LTV and gain more loyal customers.

In preparation for 1C Expert certification, on the eve of two very important and global topics - blocking, I would like to look at something without which the above concepts are impossible - a DBMS transaction.

Transaction- a logically connected, indivisible sequence of actions. The transaction can either be completed in its entirety or not at all. To commit a transaction in the DBMS, the COMMIT method is used.

A typical example of a transaction is the transfer of funds from one account to another:

  1. start a transaction;
  2. read the amount of funds in account number 123;
  3. reduce account balance 123 by 100 rubles;
  4. save account balance number 123;
  5. read the amount of funds in account number 321;
  6. increase your balance by 100 rubles;
  7. record the new amount of funds in account 321;
  8. commit the transaction.

Get 267 video lessons on 1C for free:

As we can see, if a transaction is not completed completely, then it has no meaning.

Key requirements (ACID) for a transactional DBMS

One of the most common sets of requirements for transactions and transactional DBMSs is the ACID (Atomicity, Consistency, Isolation, Durability) set. These are the properties that any transaction must have:

  • Atomicity— no transaction should be recorded partially;
  • Consistency- the system is in a consistent state before the transaction begins and must remain in a consistent state after the transaction is completed;
  • Isolation— during the execution of a transaction, parallel transactions should not affect its result;
  • Durability- in the event of a failure, changes made by a successfully completed transaction must remain saved after the system returns to operation.

Transactions in 1C

Transactions in 1C 8.3 and 8.2 are created both automatically and described by the developers.

You can use the TransactionActive() method to find out whether a transaction is active.

An example of an automatic transaction is processing a document posting, writing a directory item to a database, writing a set of information register records, etc.